MeshObjectT.hh 11.3 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2
3
*                                                                            *
*                              OpenFlipper                                   *
Jan Möbius's avatar
Jan Möbius committed
4
*      Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen       *
Jan Möbius's avatar
Jan Möbius committed
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
*                           www.openflipper.org                              *
*                                                                            *
*--------------------------------------------------------------------------- *
*  This file is part of OpenFlipper.                                         *
*                                                                            *
*  OpenFlipper is free software: you can redistribute it and/or modify       *
*  it under the terms of the GNU Lesser General Public License as            *
*  published by the Free Software Foundation, either version 3 of            *
*  the License, or (at your option) any later version with the               *
*  following exceptions:                                                     *
*                                                                            *
*  If other files instantiate templates or use macros                        *
*  or inline functions from this file, or you compile this file and          *
*  link it with other files to produce an executable, this file does         *
*  not by itself cause the resulting executable to be covered by the         *
*  GNU Lesser General Public License. This exception does not however        *
*  invalidate any other reasons why the executable file might be             *
*  covered by the GNU Lesser General Public License.                         *
*                                                                            *
*  OpenFlipper is distributed in the hope that it will be useful,            *
*  but WITHOUT ANY WARRANTY; without even the implied warranty of            *
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
*  GNU Lesser General Public License for more details.                       *
*                                                                            *
*  You should have received a copy of the GNU LesserGeneral Public           *
*  License along with OpenFlipper. If not,                                   *
*  see <http://www.gnu.org/licenses/>.                                       *
*                                                                            *
33
34
35
\*===========================================================================*/

/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
36
37
38
39
40
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
41
\*===========================================================================*/
Jan Möbius's avatar
 
Jan Möbius committed
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66




//=============================================================================
//
//  Types
//
//=============================================================================

/**
 * \file Types.hh
 * This File contains the basic available datatypes in the Framework.
 */


#ifndef MESHOBJECT_HH
#define MESHOBJECT_HH

//== INCLUDES =================================================================

// -------------------- OpenMesh
#include <OpenMesh/Core/IO/MeshIO.hh>

#include <ACG/Scenegraph/SeparatorNode.hh>
67
#include <ACG/Scenegraph/EnvMapNode.hh>
Jan Möbius's avatar
 
Jan Möbius committed
68
69
70
#include <ACG/Scenegraph/ShaderNode.hh>
#include <ACG/Scenegraph/StatusNodesT.hh>

Jan Möbius's avatar
   
Jan Möbius committed
71
72
#include <OpenFlipper/common/GlobalDefines.hh>

Jan Möbius's avatar
 
Jan Möbius committed
73
74
75
76
#include <ObjectTypes/MeshObject/StatusNodeMods.hh>
#include <OpenFlipper/common/BaseObjectData.hh>

// -------------------- BSP
77
#include <ACG/Geometry/bsp/TriangleBSPT.hh>
Jan Möbius's avatar
 
Jan Möbius committed
78
79
80


#include <OpenFlipper/common/BaseObjectData.hh>
81
#include <ACG/Scenegraph/MeshNode2T.hh>
Jan Möbius's avatar
 
Jan Möbius committed
82
83
84
85
86
87
88
89
90
91
92
93



//== TYPEDEFS =================================================================

/// Texture Node
typedef ACG::SceneGraph::TextureNode                      TextureNode;

//== CLASS DEFINITION =========================================================

/** This class provides the functionality for all kind of meshes for the framework
 */
94
template < class MeshT >
Jan Möbius's avatar
   
Jan Möbius committed
95
class DLLEXPORTONLY MeshObject : public BaseObjectData {
Jan Möbius's avatar
 
Jan Möbius committed
96
97
98
99
100
101
102
103
  public:

    /** \brief copy constructor
     *
     *  Create a copy of this object
     */
    MeshObject(const MeshObject& _object);

104
105
106
107
108
109
110
    /** \brief Constructor
    *
    * This is the standard constructor for MeshObjects. As triangle and Poly Meshes are handled by this class, the 
    * typeId is passed to the MeshObject to specify it. 
    *
    * @param _typeId   This is the type Id the Object will use. Should be typeId("TriangleMesh") or typeId("PolyMesh")
    */
111
    MeshObject(DataType _typeId);
Jan Möbius's avatar
 
Jan Möbius committed
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143

    /// destructor
    virtual ~MeshObject();

	/// Reset current object, including all related nodes.
    virtual void cleanup();

  protected:

    /// Initialise current object, including all related nodes.
    virtual void init( MeshT* _mesh = 0);

  //===========================================================================
  /** @name Name and Path handling
   * @{ */
  //===========================================================================
  public:

    /// Set the name of the Object
    void setName( QString _name );


  //===========================================================================
  /** @name Content
   * @{ */
  //===========================================================================

  public:
    /// return a pointer to the mesh
    MeshT* mesh();

    /// Update the whole Object (Selection,Topology,...)
Dirk Wilden's avatar
Dirk Wilden committed
144
    virtual void update(UpdateType _type = UPDATE_ALL);
Jan Möbius's avatar
 
Jan Möbius committed
145
146
147
148
149
150
151
152
153
154
155
156
157

    /// Call this function to update the modeling regions
    void updateSelection();

    /// Call this function to update the modeling regions
    void updateModelingRegions();

    /// Update Feature Visualization Node
    void updateFeatures();

    /// Update Geometry of all data structures
    void updateGeometry();

158
159
160
    /// Update Colors of all data structures
    void updateColor();
    
Jan Möbius's avatar
 
Jan Möbius committed
161
162
163
    /// Update Topology of all data structures
    void updateTopology();

164
165
166
    /// Update Texture of all data structures
    void updateTexture();

Jan Möbius's avatar
 
Jan Möbius committed
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
    /** return a full copy of this object ( All scenegraph nodes will be created )
     *  but the object will not be a part of the object tree.
     */
    BaseObject* copy();

  private:
    MeshT*           mesh_;

  /** @} */

  //===========================================================================
  /** @name Visualization
   * @{ */
  //===========================================================================

  public:

    /// Get the TextureNode of the current mesh
185
    ACG::SceneGraph::EnvMapNode* textureNode();
Jan Möbius's avatar
 
Jan Möbius committed
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202

    /// Return pointer to the shader node
    ACG::SceneGraph::ShaderNode* shaderNode();

    /// Hide or show the selection Node of the object
    void hideSelection( bool _hide );

    /// return if the selections are currently visible
    bool selectionVisible();

    /// Hide or show the feature Node of the object
    void hideFeatures( bool _hide );

    /// return if the feature Node of the object is currently visible
    bool featuresVisible( );

    /// Hide or show the area Nodes of the object
203
    void hideArea(  StatusBits _bit, bool _hide );
Jan Möbius's avatar
 
Jan Möbius committed
204

205
206
207
208
209
210
211
212
213
    /** \brief Return if the selected areas are currently visible
     *
     * \note If the bits contain multiple area bits, than only if all are visible,
     *       this function will return true
     *
     *  @param _bit Status bit to check
     *  @return All visible?
     */
    bool areaVisible( StatusBits _bit );
Jan Möbius's avatar
 
Jan Möbius committed
214
215

    /// Get the Scenegraph Mesh Node
216
    ACG::SceneGraph::MeshNodeT<MeshT>* meshNode();
Jan Möbius's avatar
 
Jan Möbius committed
217
218

    /// Get the BoundingBox of this object
219
    void boundingBox( ACG::Vec3d& _bbMin , typename ACG::Vec3d& _bbMax );
Dirk Wilden's avatar
Dirk Wilden committed
220
221
    
    BaseNode* primaryNode();
Jan Möbius's avatar
 
Jan Möbius committed
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236

  private :
    /// Status Node for a mesh, visualizing the selection state of a mesh
    ACG::SceneGraph::SelectionNodeT<MeshT>*  statusNode_;

    /// Area selection Vis
    ACG::SceneGraph::StatusNodeT<MeshT, AreaNodeMod<MeshT> > * areaNode_;

    /// Handle selection Vis
    ACG::SceneGraph::StatusNodeT<MeshT, HandleNodeMod<MeshT> > * handleNode_;

    /// Feature selection Vis
    ACG::SceneGraph::StatusNodeT<MeshT, FeatureNodeMod<MeshT> > *featureNode_;

    /// Scenegraph Mesh Node
237
    ACG::SceneGraph::MeshNodeT<MeshT>*                     meshNode_;
Jan Möbius's avatar
 
Jan Möbius committed
238
239

    /// Scenegraph TextureNode
240
    ACG::SceneGraph::EnvMapNode*     textureNode_;
Jan Möbius's avatar
 
Jan Möbius committed
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306

    /// Scenegraph ShaderNode
    ACG::SceneGraph::ShaderNode*     shaderNode_;

  /** @} */

  //===========================================================================
  /** @name Load/Save
   * @{ */
  //===========================================================================

  public:

    /// Load a mesh from the given file
    bool loadMesh(QString _filename);

  /** @} */

  //===========================================================================
  /** @name Object Information
   * @{ */
  //===========================================================================
  public:
    /// Get all Info for the Object as a string
    QString getObjectinfo();

  /** @} */


  //===========================================================================
  /** @name Picking
   * @{ */
  //===========================================================================
  public:
    /// detect if the node has been picked
    bool picked( uint _node_idx );

    /// Enable or disable picking for this Node
    void enablePicking( bool _enable );

    /// Check if picking is enabled for this Node
    bool pickingEnabled();

  /** @} */

  //===========================================================================
  /** @name BSP Extension ( Implements a BSP for the mesh used for fast searches )
   * @{ */
  //===========================================================================
  public:

    typedef OpenMeshTriangleBSPT< MeshT > OMTriangleBSP;

    /** Get a bsp for this object. Only supported for Triangle Meshes at the moment.
     *
     *
     * @return Pointer to bsp or Null if unsupported for this type.
     */
    OMTriangleBSP* requestTriangleBsp();

    /**  If something in the mesh changes, call this function to clear the octree.
     *  You have to do a new request as the old one will be deleted.
     * @todo : Update the tree when the update function of this object is called.
     * @todo : dont recreate but update the old one.
     * @return The new pointer to the bsp or Null if unsupported
     */
307
308
309
310
311
312
313
314
315
316
     void invalidateTriangleBsp();
  
    
    /** Update the bsp for this object. Only supported for Triangle Meshes at the moment.
     *
     *
     * @return Pointer to bsp or Null if unsupported for this type.
     */
     OMTriangleBSP* resetTriangleBsp();

Jan Möbius's avatar
 
Jan Möbius committed
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335

  private :
    /// If requested a bsp is created for this object
    OMTriangleBSP* triangle_bsp_;

  /** @} */
};

//=============================================================================

#if defined(INCLUDE_TEMPLATES) && !defined(MESHOBJECT_C)
#define MESHOBJECT_TEMPLATES
#include "MeshObjectT.cc"
#endif


//=============================================================================
#endif // MESHOBJECT_HH defined
//=============================================================================