MeshObjectT.hh 9.11 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
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:
102 103 104 105 106 107 108

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

Jan Möbius's avatar
 
Jan Möbius committed
109 110
    /// constructor
    MeshObject(SeparatorNode* _rootNode);
111

Jan Möbius's avatar
 
Jan Möbius committed
112 113
    /// destructor
    virtual ~MeshObject();
114

Jan Möbius's avatar
 
Jan Möbius committed
115
	/// Reset current object, including all related nodes.
116
    virtual void cleanup();
Jan Möbius's avatar
 
Jan Möbius committed
117 118

  protected:
119

Jan Möbius's avatar
 
Jan Möbius committed
120
    /// Initialise current object, including all related nodes.
121
    virtual void init( MeshT* _mesh = 0);
122

Jan Möbius's avatar
 
Jan Möbius committed
123 124 125
  //===========================================================================
  /** @name Name and Path handling
   * @{ */
126
  //===========================================================================
Jan Möbius's avatar
 
Jan Möbius committed
127
  public:
128

Jan Möbius's avatar
 
Jan Möbius committed
129 130
    /// Set the name of the Object
    void setName( QString _name );
131 132


Jan Möbius's avatar
 
Jan Möbius committed
133 134 135 136
  //===========================================================================
  /** @name Content
   * @{ */
  //===========================================================================
137

Jan Möbius's avatar
 
Jan Möbius committed
138 139
  public:
    /// return a pointer to the mesh
140 141
    MeshT* mesh();

Jan Möbius's avatar
 
Jan Möbius committed
142 143
    /// Update the whole Object (Selection,Topology,...)
    virtual void update();
144

Jan Möbius's avatar
 
Jan Möbius committed
145 146
    /// Call this function to update the modeling regions
    void updateSelection();
147

Jan Möbius's avatar
 
Jan Möbius committed
148 149
    /// Call this function to update the modeling regions
    void updateModelingRegions();
150

Jan Möbius's avatar
 
Jan Möbius committed
151 152
    /// Update Geometry of all data structures
    void updateGeometry();
153

Jan Möbius's avatar
 
Jan Möbius committed
154 155
    /// Update Topology of all data structures
    void updateTopology();
156

157 158 159 160 161
    /** 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();

Jan Möbius's avatar
 
Jan Möbius committed
162 163
  private:
    MeshT*           mesh_;
164 165 166

  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
167 168 169
  //===========================================================================
  /** @name Visualization
   * @{ */
170 171 172 173
  //===========================================================================

  public:

Jan Möbius's avatar
 
Jan Möbius committed
174 175
    /// Get the TextureNode of the current mesh
    TextureNode* textureNode();
176

Jan Möbius's avatar
 
Jan Möbius committed
177 178
    /// Return pointer to the shader node
    ACG::SceneGraph::ShaderNode* shaderNode();
179 180 181 182 183 184 185 186

    /// 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
187
    void hideAreas( bool _hide );
188 189 190 191

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

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

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

Jan Möbius's avatar
 
Jan Möbius committed
198 199 200
  private :
    /// Status Node for a mesh, visualizing the selection state of a mesh
    ACG::SceneGraph::SelectionNodeT<MeshT>*  statusNode_;
201

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

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

Jan Möbius's avatar
 
Jan Möbius committed
208 209
    /// Scenegraph Mesh Node
    ACG::SceneGraph::MeshNodeT<MeshT>*                     meshNode_;
210

Jan Möbius's avatar
 
Jan Möbius committed
211 212
    /// Scenegraph TextureNode
    TextureNode*     textureNode_;
213

Jan Möbius's avatar
 
Jan Möbius committed
214 215
    /// Scenegraph ShaderNode
    ACG::SceneGraph::ShaderNode*     shaderNode_;
216 217 218

  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
219 220 221
  //===========================================================================
  /** @name Load/Save
   * @{ */
222 223
  //===========================================================================

Jan Möbius's avatar
 
Jan Möbius committed
224
  public:
225

Jan Möbius's avatar
 
Jan Möbius committed
226 227
    /// Load a mesh from the given file
    bool loadMesh(QString _filename);
228 229 230

  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
231 232 233
  //===========================================================================
  /** @name Object Information
   * @{ */
234
  //===========================================================================
Jan Möbius's avatar
 
Jan Möbius committed
235 236 237
  public:
    /// Get all Info for the Object as a string
    QString getObjectinfo();
238 239 240 241

  /** @} */


Jan Möbius's avatar
 
Jan Möbius committed
242 243 244
  //===========================================================================
  /** @name Picking
   * @{ */
245
  //===========================================================================
Jan Möbius's avatar
 
Jan Möbius committed
246 247 248
  public:
    /// detect if the node has been picked
    bool picked( uint _node_idx );
249 250 251 252 253 254

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

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

  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
258 259 260
  //===========================================================================
  /** @name Texture Handling
   * @{ */
261
  //===========================================================================
Jan Möbius's avatar
 
Jan Möbius committed
262
  public :
263

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

Jan Möbius's avatar
 
Jan Möbius committed
266 267 268 269 270 271 272
    /** 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;
273 274
  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
275 276 277
  //===========================================================================
  /** @name BSP Extension ( Implements a BSP for the mesh used for fast searches )
   * @{ */
278
  //===========================================================================
Jan Möbius's avatar
 
Jan Möbius committed
279
  public:
280

Jan Möbius's avatar
 
Jan Möbius committed
281
    typedef OpenMeshTriangleBSPT< MeshT > OMTriangleBSP;
282

Jan Möbius's avatar
 
Jan Möbius committed
283
    /** Get a bsp for this object. Only supported for Triangle Meshes at the moment.
284 285
     *
     *
Jan Möbius's avatar
 
Jan Möbius committed
286 287 288
     * @return Pointer to bsp or Null if unsupported for this type.
     */
    OMTriangleBSP* requestTriangleBsp();
289

Jan Möbius's avatar
 
Jan Möbius committed
290 291 292 293
    /**  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.
294
     * @return The new pointer to the bsp or Null if unsupported
Jan Möbius's avatar
 
Jan Möbius committed
295 296
     */
    OMTriangleBSP* resetTriangleBsp();
297

Jan Möbius's avatar
 
Jan Möbius committed
298 299 300
  private :
    /// If requested a bsp is created for this object
    OMTriangleBSP* triangle_bsp_;
301 302

  /** @} */
Jan Möbius's avatar
 
Jan Möbius committed
303 304 305 306 307
};

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

#if defined(INCLUDE_TEMPLATES) && !defined(MESHOBJECT_C)
Jan Möbius's avatar
Jan Möbius committed
308
#define MESHOBJECT_TEMPLATES
Jan Möbius's avatar
 
Jan Möbius committed
309 310
#include "MeshObjectT.cc"
#endif
311 312


Jan Möbius's avatar
 
Jan Möbius committed
313 314 315
//=============================================================================
#endif // MESHOBJECT_HH defined
//=============================================================================