PrimitivesGenerator.hh 8.75 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 53 54
#include <OpenFlipper/common/Types.hh>

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

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


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

71 72
  Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-PrimitiveGenerator")

73 74 75 76
  signals:

  //BaseInterface
  void updateView();
77
  void updatedObject(int _id, const UpdateType& _type);
78 79 80 81 82 83 84 85 86 87 88 89
  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);

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

93 94
public:

Jan Möbius's avatar
Jan Möbius committed
95 96 97
  PrimitivesGeneratorPlugin();
  ~PrimitivesGeneratorPlugin();

98
  // BaseInterface
99
  QString name() { return (QString("Primitives Generator"));  } ;
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
  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"); };

115 116 117 118 119 120 121 122 123 124
  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);

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

128 129 130 131 132 133
  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);

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

137 138 139 140 141 142 143 144 145 146 147
  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);
148

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

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

157
#ifdef ENABLE_POLYHEDRALMESH_SUPPORT
158 159 160 161 162 163 164 165 166
  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
167 168 169 170
#ifdef ENABLE_HEXAHEDRALMESH_SUPPORT
  int addHexahedralCube(const Vector& _position = Vector(0.0,0.0,0.0),
                         const double _length = 2.0);
#endif
171

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

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

183
  inline void add_face(int _vh1 , int _vh2, int _vh3 , int _vh4);
184

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

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

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

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

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

  int slices_;
  int stacks_;

206 207
  QMenu* primitivesMenu_;

208 209 210
};

#endif //PRIMITIVESGENERATORPLUGIN_HH