Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
VolumeMeshObjectT.cc
1 /*===========================================================================*\
2 * *
3  * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40  \*===========================================================================*/
41 
42 /*===========================================================================*\
43 * *
44  * $Revision$ *
45  * $LastChangedBy$ *
46  * $Date$ *
47  * *
48  \*===========================================================================*/
49 
50 //=============================================================================
51 //
52 // MyTypes
53 //
54 //=============================================================================
55 
56 #define VOLUMEMESHOBJECTT_CC
57 
58 //== INCLUDES =================================================================
59 
60 #include "VolumeMeshObject.hh"
61 
63 #include <ACG/Scenegraph/DrawModes.hh>
66 
67 #include "VolumeMeshDrawModesContainer.hh"
68 
69 //== TYPEDEFS =================================================================
70 
71 //== CLASS DEFINITION =========================================================
72 
73 template<class MeshT>
75  BaseObjectData(_object), mesh_(_object.mesh_.get()),
76  statusAttrib_(*mesh_),
77  colorAttrib_(*mesh_),
78  normalAttrib_(*mesh_),
79  texcoordAttrib_(*mesh_),
80  meshNode_(NULL),
81  shaderNode_(NULL),
82  textureNode_(NULL)
83 {
84 
85  init();
86 
87  setName(name());
88 }
89 
90 template<class MeshT>
92  BaseObjectData(), mesh_(new MeshT()),
93  statusAttrib_(*mesh_),
94  colorAttrib_(*mesh_, ACG::Vec4f(1.0f, 1.0f, 1.0f, 1.0f) /* Default color */),
95  normalAttrib_(*mesh_),
96  texcoordAttrib_(*mesh_),
97  meshNode_(NULL),
98  shaderNode_(NULL),
99  textureNode_(NULL)
100 {
101 
102  setDataType(_typeId);
103  init();
104 }
105 
106 template<class MeshT>
108 
109  // Delete the data attached to this object (this will remove all perObject data)
110  // Not the best way to do it but it will work.
111  // This is only necessary if people use references to the mesh below and
112  // they do something with the mesh in the destructor of their
113  // perObjectData.
114  deleteData();
115 
116  // No need to delete the scenegraph nodes as this will be managed by baseplugin
117  meshNode_ = 0;
118  shaderNode_ = 0;
119  textureNode_ = 0;
120 }
121 
125 template<class MeshT>
127 
129 
130  meshNode_ = 0;
131  shaderNode_ = 0;
132  textureNode_ = 0;
133 
134  init();
135 }
136 
140 template<class MeshT>
142 
143  // Only initialize scenegraph nodes when we initialized a gui!!
144  if(OpenFlipper::Options::nogui())
145  return;
146 
147  VolumeMeshDrawModesContainer drawModes; // create this object before initializing the textureNode
148 
149  textureNode_ = new ACG::SceneGraph::TextureNode(materialNode() , "NEW TextureNode for ");
150 
151  shaderNode_ = new ACG::SceneGraph::ShaderNode(textureNode_ , "NEW ShaderNode for ");
152 
153  meshNode_ = new ACG::SceneGraph::VolumeMeshNodeT<MeshT>(*mesh_, statusAttrib_, colorAttrib_, normalAttrib_, texcoordAttrib_, materialNode(), shaderNode_, "NEW VolumeMeshNode");
154 
155  if(manipulatorNode() == NULL)
156  std::cerr << "Error when creating volume mesh object! Manipulator node is NULL!" << std::endl;
157 
158  if(materialNode() == NULL)
159  std::cerr << "Error when creating mesh object! Material node is NULL!" << std::endl;
160 
161  materialNode()->set_point_size(12.0f);
162 
163  QString shaderDir = OpenFlipper::Options::shaderDirStr() + OpenFlipper::Options::dirSeparator();
164 
165  std::string shaderDirectory = std::string( shaderDir.toUtf8() );
166  shaderNode_->setShaderDir( shaderDirectory );
167 
168  if ( QFile( shaderDir + "Phong/Vertex.glsl").exists() && QFile( shaderDir + "Phong/Fragment.glsl" ).exists() )
169  {
170  shaderNode_->setShader(drawModes.cellsPhongShaded, "Phong/Vertex.glsl" , "Phong/Fragment.glsl" );
171  shaderNode_->setShader(drawModes.facesPhongShaded, "Phong/Vertex.glsl" , "Phong/Fragment.glsl" );
172  shaderNode_->setShader(drawModes.halffacesPhongShaded,"Phong/Vertex.glsl" , "Phong/Fragment.glsl" );
173  }
174  else
175  std::cerr << "Shader Files for Phong not found!" << std::endl;
176 
177 
178  // Update all nodes
179  update();
180 }
181 
182 // ===============================================================================
183 // Name/Path Handling
184 // ===============================================================================
185 
189 template<class MeshT>
190 void VolumeMeshObject<MeshT>::setName(QString _name) {
192 
193  // No update when gui is not active
194  if(OpenFlipper::Options::nogui())
195  return;
196 
197  std::string meshnodename = std::string("VolumeMeshNode for mesh " + _name.toUtf8());
198  meshNode_->name(meshnodename);
199 
200  std::string shadernodename = std::string("ShaderNode for mesh " + _name.toUtf8());
201  shaderNode_->name(shadernodename);
202 
203  std::string texturenodename = std::string("TextureNode for mesh " + _name.toUtf8());
204  textureNode_->name(texturenodename);
205 }
206 
207 // ===============================================================================
208 // Content
209 // ===============================================================================
210 
214 template<class MeshT>
216  return mesh_.get();
217 }
218 
223 template<class MeshT>
225 
226  // No update necessary if no gui
227  if(OpenFlipper::Options::nogui())
228  return;
229 
231 
232  if(_type.contains(UPDATE_ALL) || _type.contains(UPDATE_TOPOLOGY)) {
233  updateGeometry();
234  updateColor();
235  updateTopology();
236  updateSelection();
237  } else {
238  if(_type.contains(UPDATE_GEOMETRY)) {
239  updateGeometry();
240  }
241  if(_type.contains(UPDATE_SELECTION)) {
242  updateSelection();
243  }
244  if(_type.contains(UPDATE_COLOR)) {
245  updateColor();
246  }
247  if (_type.contains(UPDATE_TEXTURE)){
248  updateTexture();
249  }
250  }
251 }
252 
254 template<class MeshT>
256 
257  if(meshNode_) {
258  meshNode_->set_selection_changed(true);
259  }
260 }
261 
263 template<class MeshT>
265 
266  normalAttrib_.update_face_normals();
267 
268  if(meshNode_) {
269  meshNode_->set_geometry_changed(true);
270  }
271 }
272 
274 template<class MeshT>
276 
277  if(meshNode_)
278  meshNode_->set_color_changed(true);
279 }
280 
282 template<class MeshT>
284 {
285  if(meshNode_)
286  meshNode_->set_texture_changed(true);
287 
288 }
289 
291 template<class MeshT>
293  if(meshNode_) {
294  meshNode_->set_topology_changed(true);
295  }
296 }
297 
298 template<class MeshT>
301  return dynamic_cast<BaseObject*> (object);
302 }
303 
304 template<class MeshT>
306 {
307  return shaderNode_;
308 }
309 
310 template<class MeshT>
312 {
313  return textureNode_;
314 }
315 
316 // ===============================================================================
317 // Visualization
318 // ===============================================================================
322 template<class MeshT>
324  return meshNode_;
325 }
326 
329 template<class MeshT>
331  if(meshNode_) {
332  _bbMin = ACG::Vec3d(FLT_MAX, FLT_MAX, FLT_MAX);
333  _bbMax = ACG::Vec3d(-FLT_MAX, -FLT_MAX, -FLT_MAX);
334  meshNode_->boundingBox(_bbMin, _bbMax);
335  } else {
336  std::cerr << "Error: Bounding box computation via Scenegraph not available without gui." << std::endl;
337  }
338 }
339 
340 // ===============================================================================
341 // Object information
342 // ===============================================================================
343 
349 template<class MeshT>
351  QString output;
352 
353  output += "========================================================================\n";
354  output += BaseObjectData::getObjectinfo();
355 
356  if(dataType(typeId("PolyhedralMesh")))
357  output += "Object Contains Polyhedral Mesh : ";
358 
359  if(dataType(typeId("HexahedralMesh")))
360  output += "Object Contains Hexahedral Mesh : ";
361 
362  output += QString::number(mesh()->n_vertices()) + " vertices\n";
363  output += QString::number(mesh()->n_edges()) += " edges\n";
364  output += QString::number(mesh()->n_halfedges()) += " half-edges\n";
365  output += QString::number(mesh()->n_faces()) += " faces\n";
366  output += QString::number(mesh()->n_halffaces()) += " half-faces\n";
367  output += QString::number(mesh()->n_cells()) += " cells\n";
368 
369  output += "========================================================================\n";
370  return output;
371 }
372 
373 // ===============================================================================
374 // Picking
375 // ===============================================================================
376 
383 template<class MeshT>
384 bool VolumeMeshObject<MeshT>::picked(unsigned int _node_idx) {
385  return (_node_idx == meshNode_->id());
386 }
387 
388 template<class MeshT>
390  if(OpenFlipper::Options::nogui())
391  return;
392 
393  meshNode_->enablePicking(_enable);
394  shaderNode_->enablePicking(_enable);
395 }
396 
397 template<class MeshT>
399  return meshNode_->pickingEnabled();
400 }
401 
402 //=============================================================================
403 
404 template<class MeshT>
405 BaseNode*
407  return boundingBoxNode();
408 }
409 
410 //=============================================================================
DLLEXPORT DataType typeId(QString _name)
Given a dataType Identifier string this function will return the id of the datatype.
Definition: Types.cc:150
VolumeMeshObject(const VolumeMeshObject &_object)
copy constructor
ACG::SceneGraph::ShaderNode ShaderNode
Simple Name for ShaderNode.
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
MeshT * mesh()
return a pointer to the mesh
const UpdateType UPDATE_GEOMETRY(UpdateTypeSet(1)<< 2)
Geometry updated.
void updateTopology()
Update Topology of all data structures.
virtual QString getObjectinfo()
Get all Info for the Object as a string.
Definition: BaseObject.cc:255
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:741
bool contains(const UpdateType &_type) const
Check if this update contains the given UpdateType.
Definition: UpdateType.cc:111
Update type class.
Definition: UpdateType.hh:70
bool pickingEnabled()
Check if picking is enabled for this Node.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
void setName(QString _name)
Set the name of the Object.
VectorT< double, 3 > Vec3d
Definition: VectorT.hh:127
virtual void cleanup()
const UpdateType UPDATE_SELECTION(UpdateTypeSet(1)<< 4)
Selection updated.
virtual void cleanup()
Reset current object, including all related nodes.
void updateTexture()
Update Texture of all data structures.
void updateGeometry()
Update Geometry of all data structures.
QString getObjectinfo()
Get all Info for the Object as a string.
void updateSelection()
Call this function to update the selection.
ACG::SceneGraph::TextureNode * textureNode()
Return pointer to the texture node.
ACG::SceneGraph::VolumeMeshNodeT< MeshT > * meshNode()
Get the Scenegraph Mesh Node.
BaseObject * copy()
const UpdateType UPDATE_TEXTURE(UpdateTypeSet(1)<< 11)
Textures have changed.
void setDataType(DataType _type)
Definition: BaseObject.cc:244
const UpdateType UPDATE_TOPOLOGY(UpdateTypeSet(1)<< 3)
Topology updated.
void boundingBox(ACG::Vec3d &_bbMin, typename ACG::Vec3d &_bbMax)
Get the BoundingBox of this object.
ACG::SceneGraph::ShaderNode * shaderNode()
Return pointer to the shader node.
bool picked(unsigned int _node_idx)
detect if the node has been picked
virtual void update(UpdateType _type=UPDATE_ALL)
Update the whole Object (Selection,Topology,...)
void enablePicking(bool _enable)
Enable or disable picking for this Node.
virtual ~VolumeMeshObject()
destructor
const UpdateType UPDATE_COLOR(UpdateTypeSet(1)<< 10)
Colors have changed.
void updateColor()
Update Colors of all data structures.
Predefined datatypes.
Definition: DataTypes.hh:96
void setMainGLContext()
Set current GL Context to main context.
BaseNode * primaryNode()
Scenegraph Mesh Node.
This class provides easy access to DrawModes supported by OpenVolumeMesh.
virtual void init()
Initialise current object, including all related nodes.