PrimitivesGenerator.hh 8.85 KB
Newer Older
1 2 3
/*===========================================================================*\
*                                                                            *
 *                              OpenFlipper                                   *
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
 *           Copyright (c) 2001-2015, RWTH-Aachen University                 *
 *           Department of Computer Graphics and Multimedia                  *
 *                          All rights reserved.                             *
 *                            www.openflipper.org                            *
 *                                                                           *
 *---------------------------------------------------------------------------*
 * This file is part of OpenFlipper.                                         *
 *---------------------------------------------------------------------------*
 *                                                                           *
 * Redistribution and use in source and binary forms, with or without        *
 * modification, are permitted provided that the following conditions        *
 * are met:                                                                  *
 *                                                                           *
 * 1. Redistributions of source code must retain the above copyright notice, *
 *    this list of conditions and the following disclaimer.                  *
 *                                                                           *
 * 2. Redistributions in binary form must reproduce the above copyright      *
 *    notice, this list of conditions and the following disclaimer in the    *
 *    documentation and/or other materials provided with the distribution.   *
 *                                                                           *
 * 3. Neither the name of the copyright holder nor the names of its          *
 *    contributors may be used to endorse or promote products derived from   *
 *    this software without specific prior written permission.               *
 *                                                                           *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       *
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           *
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  *
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,       *
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR        *
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    *
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      *
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        *
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              *
39 40 41 42 43 44 45 46 47 48 49
 *                                                                            *
 \*===========================================================================*/


#ifndef PRIMITIVESGENERATORPLUGIN_HH
#define PRIMITIVESGENERATORPLUGIN_HH

#include <OpenFlipper/BasePlugin/BaseInterface.hh>
#include <OpenFlipper/BasePlugin/LoggingInterface.hh>
#include <OpenFlipper/BasePlugin/MenuInterface.hh>
#include <OpenFlipper/BasePlugin/LoadSaveInterface.hh>
50
#include <OpenFlipper/BasePlugin/RPCInterface.hh>
51
#include <OpenFlipper/BasePlugin/BackupInterface.hh>
52
#include <OpenFlipper/BasePlugin/PythonInterface.hh>
53 54 55
#include <OpenFlipper/common/Types.hh>

#include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
Jan Möbius's avatar
Jan Möbius committed
56
#include <ObjectTypes/PolyMesh/PolyMesh.hh>
57

58
#ifdef ENABLE_POLYHEDRALMESH_SUPPORT
59 60 61 62
#include <ObjectTypes/PolyhedralMesh/PolyhedralMesh.hh>
#endif


63
class PrimitivesGeneratorPlugin: public QObject, BaseInterface, LoggingInterface, MenuInterface, LoadSaveInterface, RPCInterface, BackupInterface, PythonInterface {
64 65 66 67 68
  Q_OBJECT
  Q_INTERFACES(BaseInterface)
  Q_INTERFACES(LoggingInterface)
  Q_INTERFACES(MenuInterface)
  Q_INTERFACES(LoadSaveInterface)
69
  Q_INTERFACES(RPCInterface)
70
  Q_INTERFACES(BackupInterface)
71
  Q_INTERFACES(PythonInterface)
72

73 74
  Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-PrimitiveGenerator")

75 76 77 78
  signals:

  //BaseInterface
  void updateView();
79
  void updatedObject(int _id, const UpdateType& _type);
80 81 82 83 84 85 86 87 88 89 90 91
  void setSlotDescription(QString     _slotName,   QString     _slotDescription,
                          QStringList _parameters, QStringList _descriptions);
  //LoggingInterface
  void log(Logtype _type, QString _message);
  void log(QString _message);

  // Menu Interface
  void getMenubarMenu (QString _name, QMenu *& _menu, bool _create);

  // LoadSaveInterface
  void addEmptyObject( DataType _type, int& _id);

92 93 94
  // BackupInterface
  void createBackup( int _objectid, QString _name, UpdateType _type = UPDATE_ALL);

95 96
public:

Jan Möbius's avatar
Jan Möbius committed
97 98 99
  PrimitivesGeneratorPlugin();
  ~PrimitivesGeneratorPlugin();

100
  // BaseInterface
101
  QString name() { return (QString("PrimitivesGenerator"));  } ;
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
  QString description() {  return (QString("Plugin used for generating basic primitives")); } ;

private slots:

  /// BaseInterface
  void initializePlugin();
  void pluginsInitialized();

  /// Tell system that this plugin runs without ui
  void noguiSupported( ) {} ;

public slots:

  QString version() { return QString("1.0"); };

117 118 119 120 121 122 123 124 125 126
  int addTriangulatedCylinder(const Vector& _position = Vector(0.0,0.0,0.0),
                              const Vector& _axis     = Vector(0.0,0.0,1.0),
                              const double _radius   = 1.0,
                              const double _height   = 5.0,
                              const bool   _top      = true,
                              const bool   _bottom   = true);

  int addSphere(const Vector& _position = Vector(0.0,0.0,0.0),
                const double _radius = 1.0);

127 128 129
  int addSubdivisionSphere(const Vector& _position = Vector(0.0,0.0,0.0),
                const double _radius = 1.0);

130 131 132 133 134 135
  int addTetrahedron(const Vector& _position = Vector(0.0,0.0,0.0),
                const double _length = 2.0);

  int addPyramid(const Vector& _position = Vector(0.0,0.0,0.0),
                 const double _length = 2.0);

136 137 138
  int addCube(const Vector& _position = Vector(0.0,0.0,0.0),
              const double _length = 2.0);

139 140 141 142 143 144 145 146 147 148 149
  int addTriangulatedCube(const Vector& _position = Vector(0.0,0.0,0.0),
                          const double _length = 2.0);

  int addIcosahedron(const Vector& _position = Vector(0.0,0.0,0.0),
                     const double _length = 2.0);

  int addOctahedron(const Vector& _position = Vector(0.0,0.0,0.0),
                    const double _length = 2.0);

  int addDodecahedron(const Vector& _position = Vector(0.0,0.0,0.0),
                      const double _length = 2.0);
150

151 152 153 154
#ifdef ENABLE_BSPLINECURVE_SUPPORT
  int addRandomBSplineCurve(const Vector& _position = Vector(0, 0, 0), int nDiv = 5);
#endif

155 156 157 158
#ifdef ENABLE_BSPLINESURFACE_SUPPORT
  int addRandomBSplineSurface(const Vector& _position = Vector(0, 0, 0), int nDiv = 5);
#endif

159
#ifdef ENABLE_POLYHEDRALMESH_SUPPORT
160 161 162 163 164 165 166 167 168
  int addTetrahedralCube(const Vector& _position = Vector(0.0,0.0,0.0),
                         const double _length = 2.0);

  int addTetrahedralCuboid(const Vector& _position = Vector(0.0,0.0,0.0),
                           const Vector& _length = Vector(4.0,6.0,12.0),
                           const unsigned int n_x = 5,
                           const unsigned int n_y = 5,
                           const unsigned int n_z = 10);
#endif
169 170 171 172
#ifdef ENABLE_HEXAHEDRALMESH_SUPPORT
  int addHexahedralCube(const Vector& _position = Vector(0.0,0.0,0.0),
                         const double _length = 2.0);
#endif
173

174 175
private:
  int addTriMesh();
Jan Möbius's avatar
Jan Möbius committed
176
  int addPolyMesh();
177 178
  // construct Octahedron in triMesh_
  void constructOctahedron(const Vector& _position, const double _length);
179

180
#ifdef ENABLE_POLYHEDRALMESH_SUPPORT
181 182
  int addPolyhedralMesh();
#endif
183
  inline void add_face(int _vh1 , int _vh2, int _vh3);
184

185
  inline void add_face(int _vh1 , int _vh2, int _vh3 , int _vh4);
186

Jan Möbius's avatar
Jan Möbius committed
187 188
  inline void add_face( int _vh1 , int _vh2, int _vh3, int _vh4 , int _vh5 );

189 190 191 192 193 194 195
  inline ACG::Vec3d positionOnCylinder(const int _sliceNumber,
                                       const int _stackNumber,
                                       const Vector _position ,
                                       const Vector _axis,
                                       const double _radius,
                                       const double _height);

196
  inline ACG::Vec3d positionOnSphere(int _sliceNumber, int _stackNumber, const double _radius, const Vector& _position);
197 198
  inline ACG::Vec2f texCoordOnSphere(int _sliceNumber, int _stackNumber);

199
  std::vector<TriMesh::VertexHandle> vhandles_;
Jan Möbius's avatar
Jan Möbius committed
200
  std::vector<PolyMesh::VertexHandle> vphandles_;
201

Jan Möbius's avatar
Jan Möbius committed
202 203
  TriMesh*  triMesh_;
  PolyMesh* polyMesh_;
204 205 206 207

  int slices_;
  int stacks_;

208 209
  QMenu* primitivesMenu_;

210 211 212
};

#endif //PRIMITIVESGENERATORPLUGIN_HH