PrimitivesGenerator.hh 9.23 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
1 2 3
/*===========================================================================*\
*                                                                            *
 *                              OpenFlipper                                   *
Martin Schultz's avatar
Martin Schultz committed
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.              *
Jan Möbius's avatar
Jan Möbius committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
 *                                                                            *
 \*===========================================================================*/

/*===========================================================================*\
*                                                                            *
 *   $Revision$                                                       *
 *   $LastChangedBy$                                                *
 *   $Date$                     *
 *                                                                            *
 \*===========================================================================*/

#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>
57
#include <OpenFlipper/BasePlugin/RPCInterface.hh>
58
#include <OpenFlipper/BasePlugin/BackupInterface.hh>
Jan Möbius's avatar
Jan Möbius committed
59 60 61
#include <OpenFlipper/common/Types.hh>

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

64
#ifdef ENABLE_POLYHEDRALMESH_SUPPORT
65 66 67 68
#include <ObjectTypes/PolyhedralMesh/PolyhedralMesh.hh>
#endif


69
class PrimitivesGeneratorPlugin: public QObject, BaseInterface, LoggingInterface, MenuInterface, LoadSaveInterface, RPCInterface, BackupInterface {
Jan Möbius's avatar
Jan Möbius committed
70 71 72 73 74
  Q_OBJECT
  Q_INTERFACES(BaseInterface)
  Q_INTERFACES(LoggingInterface)
  Q_INTERFACES(MenuInterface)
  Q_INTERFACES(LoadSaveInterface)
75
  Q_INTERFACES(RPCInterface)
76
  Q_INTERFACES(BackupInterface)
Jan Möbius's avatar
Jan Möbius committed
77

Matthias Möller's avatar
Matthias Möller committed
78 79
  Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-PrimitiveGenerator")

Jan Möbius's avatar
Jan Möbius committed
80 81 82 83
  signals:

  //BaseInterface
  void updateView();
84
  void updatedObject(int _id, const UpdateType& _type);
Jan Möbius's avatar
Jan Möbius committed
85 86 87 88 89 90 91 92 93 94 95 96
  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);

97 98 99
  // BackupInterface
  void createBackup( int _objectid, QString _name, UpdateType _type = UPDATE_ALL);

Jan Möbius's avatar
Jan Möbius committed
100 101
public:

Jan Möbius's avatar
Jan Möbius committed
102 103 104
  PrimitivesGeneratorPlugin();
  ~PrimitivesGeneratorPlugin();

Jan Möbius's avatar
Jan Möbius committed
105
  // BaseInterface
106
  QString name() { return (QString("Primitives Generator"));  } ;
Jan Möbius's avatar
Jan Möbius committed
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
  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"); };

122 123 124 125 126 127 128 129 130 131
  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);

132 133 134
  int addSubdivisionSphere(const Vector& _position = Vector(0.0,0.0,0.0),
                const double _radius = 1.0);

135 136 137 138 139 140
  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);

141 142 143
  int addCube(const Vector& _position = Vector(0.0,0.0,0.0),
              const double _length = 2.0);

144 145 146 147 148 149 150 151 152 153 154
  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);
Jan Möbius's avatar
Jan Möbius committed
155

156 157 158 159
#ifdef ENABLE_BSPLINECURVE_SUPPORT
  int addRandomBSplineCurve(const Vector& _position = Vector(0, 0, 0), int nDiv = 5);
#endif

160 161 162 163
#ifdef ENABLE_BSPLINESURFACE_SUPPORT
  int addRandomBSplineSurface(const Vector& _position = Vector(0, 0, 0), int nDiv = 5);
#endif

164
#ifdef ENABLE_POLYHEDRALMESH_SUPPORT
165 166 167 168 169 170 171 172 173
  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
174 175 176 177
#ifdef ENABLE_HEXAHEDRALMESH_SUPPORT
  int addHexahedralCube(const Vector& _position = Vector(0.0,0.0,0.0),
                         const double _length = 2.0);
#endif
178

Jan Möbius's avatar
Jan Möbius committed
179 180
private:
  int addTriMesh();
Jan Möbius's avatar
Jan Möbius committed
181
  int addPolyMesh();
182 183
  // construct Octahedron in triMesh_
  void constructOctahedron(const Vector& _position, const double _length);
Jan Möbius's avatar
Jan Möbius committed
184

185
#ifdef ENABLE_POLYHEDRALMESH_SUPPORT
186 187
  int addPolyhedralMesh();
#endif
188
  inline void add_face(int _vh1 , int _vh2, int _vh3);
189

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

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

194 195 196 197 198 199 200
  inline ACG::Vec3d positionOnCylinder(const int _sliceNumber,
                                       const int _stackNumber,
                                       const Vector _position ,
                                       const Vector _axis,
                                       const double _radius,
                                       const double _height);

201
  inline ACG::Vec3d positionOnSphere(int _sliceNumber, int _stackNumber, const double _radius, const Vector& _position);
202 203
  inline ACG::Vec2f texCoordOnSphere(int _sliceNumber, int _stackNumber);

Jan Möbius's avatar
Jan Möbius committed
204
  std::vector<TriMesh::VertexHandle> vhandles_;
Jan Möbius's avatar
Jan Möbius committed
205
  std::vector<PolyMesh::VertexHandle> vphandles_;
Jan Möbius's avatar
Jan Möbius committed
206

Jan Möbius's avatar
Jan Möbius committed
207 208
  TriMesh*  triMesh_;
  PolyMesh* polyMesh_;
209 210 211 212

  int slices_;
  int stacks_;

Jan Möbius's avatar
Jan Möbius committed
213 214
  QMenu* primitivesMenu_;

Jan Möbius's avatar
Jan Möbius committed
215 216 217
};

#endif //PRIMITIVESGENERATORPLUGIN_HH