MeshObjectT.hh 8.77 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifdef WIN32
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT
#endif

//== 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>

67
/// Additional Node status Bits for Mesh
Jan Möbius's avatar
 
Jan Möbius committed
68
69
70
71
72
73
74
75
76
77
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"
78

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


83
84
85
86
#include "BaseObjectData.hh"



Jan Möbius's avatar
 
Jan Möbius committed
87
88

//== TYPEDEFS =================================================================
89

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

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

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

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

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

  protected:
110

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

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

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


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

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

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

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

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

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

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

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

  /** @} */

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

  public:

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

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

    /// 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
173
    void hideAreas( bool _hide );
174
175
176
177

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

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

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

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

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

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

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

Jan Möbius's avatar
 
Jan Möbius committed
197
198
    /// Scenegraph TextureNode
    TextureNode*     textureNode_;
199

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

  /** @} */

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

Jan Möbius's avatar
 
Jan Möbius committed
210
  public:
211

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

  /** @} */

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

  /** @} */


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

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

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

  /** @} */

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

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

Jan Möbius's avatar
 
Jan Möbius committed
252
253
254
255
256
257
258
    /** 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;
259
260
  /** @} */

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

Jan Möbius's avatar
 
Jan Möbius committed
267
    typedef OpenMeshTriangleBSPT< MeshT > OMTriangleBSP;
268

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

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

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

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

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

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


Jan Möbius's avatar
 
Jan Möbius committed
299
300
301
//=============================================================================
#endif // MESHOBJECT_HH defined
//=============================================================================