PrimitivesGenerator.hh 9.1 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 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>
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>
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 {
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)
77

78 79 80 81
#if QT_VERSION >= 0x050000
  Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-PrimitiveGenerator")
#endif

82 83 84 85
  signals:

  //BaseInterface
  void updateView();
86
  void updatedObject(int _id, const UpdateType& _type);
87 88 89 90 91 92 93 94 95 96 97 98
  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);

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

102 103
public:

Jan Möbius's avatar
Jan Möbius committed
104 105 106
  PrimitivesGeneratorPlugin();
  ~PrimitivesGeneratorPlugin();

107
  // BaseInterface
108
  QString name() { return (QString("Primitives Generator"));  } ;
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
  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"); };

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

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

137 138 139 140 141 142
  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);

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

146 147 148 149 150 151 152 153 154 155 156
  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);
157

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

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

166
#ifdef ENABLE_POLYHEDRALMESH_SUPPORT
167 168 169 170 171 172 173 174 175 176
  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

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

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

188
  inline void add_face(int _vh1 , int _vh2, int _vh3 , int _vh4);
189

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

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

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

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

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

  int slices_;
  int stacks_;

211 212
  QMenu* primitivesMenu_;

213 214 215
};

#endif //PRIMITIVESGENERATORPLUGIN_HH