MeshObjectT.hh 8.79 KB
Newer Older
Jan Möbius's avatar
 
Jan Möbius committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//=============================================================================
//
//                               OpenFlipper
//        Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
//                           www.openflipper.org
//
//-----------------------------------------------------------------------------
//
//                                License
//
//  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.
15
//
Jan Möbius's avatar
 
Jan Möbius committed
16
17
18
19
//  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.
20
//
Jan Möbius's avatar
 
Jan Möbius committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//  You should have received a copy of the GNU Lesser General Public License
//  along with OpenFlipper.  If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
//   $Revision$
//   $Author$
//   $Date$
//
//=============================================================================




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

/**
42
 * \file Types.hh
Jan Möbius's avatar
 
Jan Möbius committed
43
44
45
46
47
48
49
 * This File contains the basic available datatypes in the Framework.
 */


#ifndef MESHOBJECT_HH
#define MESHOBJECT_HH

50

Jan Möbius's avatar
Jan Möbius committed
51
#ifndef DLLEXPORT
Jan Möbius's avatar
 
Jan Möbius committed
52
53
54
55
56
#ifdef WIN32
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT
#endif
Jan Möbius's avatar
Jan Möbius committed
57
#endif 
Jan Möbius's avatar
 
Jan Möbius committed
58
59
60
61
62
63
64
65
66
67
68

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

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

#include <ACG/Scenegraph/SeparatorNode.hh>
#include <ACG/Scenegraph/TextureNode.hh>
#include <ACG/Scenegraph/ShaderNode.hh>
#include <ACG/Scenegraph/StatusNodesT.hh>

69
/// Additional Node status Bits for Mesh
Jan Möbius's avatar
 
Jan Möbius committed
70
71
72
73
74
75
76
77
78
79
enum StatusBits {
   /// Modifyable area
   AREA      = OpenMesh::Attributes::UNUSED << 1,
   /// Handle Area
   HANDLEAREA = OpenMesh::Attributes::UNUSED << 2
};

#include "StatusNodeMods.hh"
#include "TriangleMeshTypes.hh"
#include "PolyMeshTypes.hh"
80

Jan Möbius's avatar
 
Jan Möbius committed
81
82
83
84
// -------------------- BSP
#include <OpenFlipper/common/bsp/TriangleBSPT.hh>


85
86
87
88
#include "BaseObjectData.hh"



Jan Möbius's avatar
 
Jan Möbius committed
89
90

//== TYPEDEFS =================================================================
91

Jan Möbius's avatar
 
Jan Möbius committed
92
/// Texture Node
93
typedef ACG::SceneGraph::TextureNode                      TextureNode;
Jan Möbius's avatar
 
Jan Möbius committed
94
95
96
97
98

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

/** This class provides the functionality for all kind of meshes for the framework
 */
99
template < class MeshT, DataType objectDataType >
Jan Möbius's avatar
 
Jan Möbius committed
100
class DLLEXPORT MeshObject : public BaseObjectData {
101
  public:
Jan Möbius's avatar
 
Jan Möbius committed
102
103
    /// constructor
    MeshObject(SeparatorNode* _rootNode);
104

Jan Möbius's avatar
 
Jan Möbius committed
105
106
    /// destructor
    virtual ~MeshObject();
107

Jan Möbius's avatar
 
Jan Möbius committed
108
	/// Reset current object, including all related nodes.
109
    virtual void cleanup();
Jan Möbius's avatar
 
Jan Möbius committed
110
111

  protected:
112

Jan Möbius's avatar
 
Jan Möbius committed
113
    /// Initialise current object, including all related nodes.
114
115
    virtual void init();

Jan Möbius's avatar
 
Jan Möbius committed
116
117
118
  //===========================================================================
  /** @name Name and Path handling
   * @{ */
119
  //===========================================================================
Jan Möbius's avatar
 
Jan Möbius committed
120
  public:
121

Jan Möbius's avatar
 
Jan Möbius committed
122
123
    /// Set the name of the Object
    void setName( QString _name );
124
125


Jan Möbius's avatar
 
Jan Möbius committed
126
127
128
129
  //===========================================================================
  /** @name Content
   * @{ */
  //===========================================================================
130

Jan Möbius's avatar
 
Jan Möbius committed
131
132
  public:
    /// return a pointer to the mesh
133
134
    MeshT* mesh();

Jan Möbius's avatar
 
Jan Möbius committed
135
136
    /// Update the whole Object (Selection,Topology,...)
    virtual void update();
137

Jan Möbius's avatar
 
Jan Möbius committed
138
139
    /// Call this function to update the modeling regions
    void updateSelection();
140

Jan Möbius's avatar
 
Jan Möbius committed
141
142
    /// Call this function to update the modeling regions
    void updateModelingRegions();
143

Jan Möbius's avatar
 
Jan Möbius committed
144
145
    /// Update Geometry of all data structures
    void updateGeometry();
146

Jan Möbius's avatar
 
Jan Möbius committed
147
148
    /// Update Topology of all data structures
    void updateTopology();
149

Jan Möbius's avatar
 
Jan Möbius committed
150
151
  private:
    MeshT*           mesh_;
152
153
154

  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
155
156
157
  //===========================================================================
  /** @name Visualization
   * @{ */
158
159
160
161
  //===========================================================================

  public:

Jan Möbius's avatar
 
Jan Möbius committed
162
163
    /// Get the TextureNode of the current mesh
    TextureNode* textureNode();
164

Jan Möbius's avatar
 
Jan Möbius committed
165
166
    /// Return pointer to the shader node
    ACG::SceneGraph::ShaderNode* shaderNode();
167
168
169
170
171
172
173
174

    /// 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 area Nodes of the object
Jan Möbius's avatar
Jan Möbius committed
175
    void hideAreas( bool _hide );
176
177
178
179

    /// return if the areas are currently visible
    bool areasVisible();

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

Jan Möbius's avatar
 
Jan Möbius committed
183
184
    /// Get the BoundingBox of this object
    void boundingBox( ACG::Vec3f& _bbMin , typename ACG::Vec3f& _bbMax );
185

Jan Möbius's avatar
 
Jan Möbius committed
186
187
188
  private :
    /// Status Node for a mesh, visualizing the selection state of a mesh
    ACG::SceneGraph::SelectionNodeT<MeshT>*  statusNode_;
189

Jan Möbius's avatar
 
Jan Möbius committed
190
191
    /// Area selection Vis
    ACG::SceneGraph::StatusNodeT<MeshT, AreaNodeMod<MeshT> > * areaNode_;
192

Jan Möbius's avatar
 
Jan Möbius committed
193
194
    /// Handle selection Vis
    ACG::SceneGraph::StatusNodeT<MeshT, HandleNodeMod<MeshT> > * handleNode_;
195

Jan Möbius's avatar
 
Jan Möbius committed
196
197
    /// Scenegraph Mesh Node
    ACG::SceneGraph::MeshNodeT<MeshT>*                     meshNode_;
198

Jan Möbius's avatar
 
Jan Möbius committed
199
200
    /// Scenegraph TextureNode
    TextureNode*     textureNode_;
201

Jan Möbius's avatar
 
Jan Möbius committed
202
203
    /// Scenegraph ShaderNode
    ACG::SceneGraph::ShaderNode*     shaderNode_;
204
205
206

  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
207
208
209
  //===========================================================================
  /** @name Load/Save
   * @{ */
210
211
  //===========================================================================

Jan Möbius's avatar
 
Jan Möbius committed
212
  public:
213

Jan Möbius's avatar
 
Jan Möbius committed
214
215
    /// Load a mesh from the given file
    bool loadMesh(QString _filename);
216
217
218

  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
219
220
221
  //===========================================================================
  /** @name Object Information
   * @{ */
222
  //===========================================================================
Jan Möbius's avatar
 
Jan Möbius committed
223
224
225
  public:
    /// Get all Info for the Object as a string
    QString getObjectinfo();
226
227
228
229

  /** @} */


Jan Möbius's avatar
 
Jan Möbius committed
230
231
232
  //===========================================================================
  /** @name Picking
   * @{ */
233
  //===========================================================================
Jan Möbius's avatar
 
Jan Möbius committed
234
235
236
  public:
    /// detect if the node has been picked
    bool picked( uint _node_idx );
237
238
239
240
241
242

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

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

  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
246
247
248
  //===========================================================================
  /** @name Texture Handling
   * @{ */
249
  //===========================================================================
Jan Möbius's avatar
 
Jan Möbius committed
250
  public :
251

Jan Möbius's avatar
 
Jan Möbius committed
252
    void addTexture(QString _property, QString _textureFile );
253

Jan Möbius's avatar
 
Jan Möbius committed
254
255
256
257
258
259
260
    /** This vector is used to store the available Textures, which will be handled
     *   by the texture control plugin. For meshes the first String identifies the mesh
     *   property used for the texture coordinates. The second String identifies the
     *  texture file. Use addTexture() to add additional textures. If the property does not exist,
     *  nothing happens if you select it.
     */
    std::vector< std::pair < QString , QString > > textures;
261
262
  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
263
264
265
  //===========================================================================
  /** @name BSP Extension ( Implements a BSP for the mesh used for fast searches )
   * @{ */
266
  //===========================================================================
Jan Möbius's avatar
 
Jan Möbius committed
267
  public:
268

Jan Möbius's avatar
 
Jan Möbius committed
269
    typedef OpenMeshTriangleBSPT< MeshT > OMTriangleBSP;
270

Jan Möbius's avatar
 
Jan Möbius committed
271
    /** Get a bsp for this object. Only supported for Triangle Meshes at the moment.
272
273
     *
     *
Jan Möbius's avatar
 
Jan Möbius committed
274
275
276
     * @return Pointer to bsp or Null if unsupported for this type.
     */
    OMTriangleBSP* requestTriangleBsp();
277

Jan Möbius's avatar
 
Jan Möbius committed
278
279
280
281
    /**  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.
282
     * @return The new pointer to the bsp or Null if unsupported
Jan Möbius's avatar
 
Jan Möbius committed
283
284
     */
    OMTriangleBSP* resetTriangleBsp();
285

Jan Möbius's avatar
 
Jan Möbius committed
286
287
288
  private :
    /// If requested a bsp is created for this object
    OMTriangleBSP* triangle_bsp_;
289
290

  /** @} */
Jan Möbius's avatar
 
Jan Möbius committed
291
292
293
294
295
};

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

#if defined(INCLUDE_TEMPLATES) && !defined(MESHOBJECT_C)
Jan Möbius's avatar
Jan Möbius committed
296
#define MESHOBJECT_TEMPLATES
Jan Möbius's avatar
 
Jan Möbius committed
297
298
#include "MeshObjectT.cc"
#endif
299
300


Jan Möbius's avatar
 
Jan Möbius committed
301
302
303
//=============================================================================
#endif // MESHOBJECT_HH defined
//=============================================================================