Developer Documentation
VolumeMeshObjectT_impl.hh
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 //
45 // MyTypes
46 //
47 //=============================================================================
48 
49 #define VOLUMEMESHOBJECTT_CC
50 
51 //== INCLUDES =================================================================
52 
53 #include "VolumeMeshObject.hh"
54 
56 #include <ACG/Scenegraph/DrawModes.hh>
59 
60 #include "VolumeMeshDrawModesContainer.hh"
61 
62 #include <ACG/Scenegraph/BoundingBoxNode.hh>
63 
64 //== TYPEDEFS =================================================================
65 
66 //== CLASS DEFINITION =========================================================
67 
68 template<class MeshT>
70  BaseObjectData(_object), mesh_(std::make_shared<MeshT>(*_object.mesh_.get())),
71  statusAttrib_(*mesh_),
72  colorAttrib_(*mesh_),
73  normalAttrib_(*mesh_),
74  texcoordAttrib_(*mesh_),
75  meshNode_(NULL),
76  shaderNode_(NULL),
77  textureNode_(NULL)
78 {
79 
80  init();
81 
82  setName(name());
83 }
84 
85 template<class MeshT>
87  BaseObjectData(), mesh_(new MeshT()),
89  colorAttrib_(*mesh_, ACG::Vec4f(1.0f, 1.0f, 1.0f, 1.0f) /* Default color */),
92  meshNode_(NULL),
93  shaderNode_(NULL),
94  textureNode_(NULL)
95 {
96 
97  setDataType(_typeId);
98  init();
99 }
100 
101 template<class MeshT>
103 
104  // Delete the data attached to this object (this will remove all perObject data)
105  // Not the best way to do it but it will work.
106  // This is only necessary if people use references to the mesh below and
107  // they do something with the mesh in the destructor of their
108  // perObjectData.
109  deleteData();
110 
111  // No need to delete the scenegraph nodes as this will be managed by baseplugin
112  meshNode_ = 0;
113  shaderNode_ = 0;
114  textureNode_ = 0;
115 }
116 
120 template<class MeshT>
122 
124 
125  meshNode_ = 0;
126  shaderNode_ = 0;
127  textureNode_ = 0;
128 
129  init();
130 }
131 
135 template<class MeshT>
137 
138  // Only initialize scenegraph nodes when we initialized a gui!!
139  if(OpenFlipper::Options::nogui())
140  return;
141 
142  VolumeMeshDrawModesContainer drawModes; // create this object before initializing the textureNode
143 
144  textureNode_ = new ACG::SceneGraph::TextureNode(materialNode() , "NEW TextureNode for ");
145 
146  shaderNode_ = new ACG::SceneGraph::ShaderNode(textureNode_ , "NEW ShaderNode for ");
147 
149 
150  if(manipulatorNode() == NULL)
151  std::cerr << "Error when creating volume mesh object! Manipulator node is NULL!" << std::endl;
152 
153  if(materialNode() == NULL)
154  std::cerr << "Error when creating mesh object! Material node is NULL!" << std::endl;
155 
156  materialNode()->set_point_size(12.0f);
157 
158  QString shaderDir = OpenFlipper::Options::shaderDirStr() + OpenFlipper::Options::dirSeparator();
159 
160  std::string shaderDirectory = std::string( shaderDir.toUtf8() );
161  shaderNode_->setShaderDir( shaderDirectory );
162 
163  if(!OpenFlipper::Options::coreProfile())
164  {
165  if ( QFile( shaderDir + "Phong/Vertex.glsl").exists() && QFile( shaderDir + "Phong/Fragment.glsl" ).exists() )
166  {
167  shaderNode_->setShader(drawModes.cellsPhongShaded, "Phong/Vertex.glsl" , "Phong/Fragment.glsl" );
168  shaderNode_->setShader(drawModes.facesPhongShaded, "Phong/Vertex.glsl" , "Phong/Fragment.glsl" );
169  shaderNode_->setShader(drawModes.halffacesPhongShaded,"Phong/Vertex.glsl" , "Phong/Fragment.glsl" );
170  }
171  else
172  std::cerr << "Shader Files for Phong not found!" << std::endl;
173  }
174 
175  // Update all nodes
176  update();
177 }
178 
179 // ===============================================================================
180 // Name/Path Handling
181 // ===============================================================================
182 
186 template<class MeshT>
187 void VolumeMeshObject<MeshT>::setName(QString _name) {
189 
190  // No update when gui is not active
191  if(OpenFlipper::Options::nogui())
192  return;
193 
194  std::string meshnodename = std::string("VolumeMeshNode for mesh " + _name.toUtf8());
195  meshNode_->name(meshnodename);
196 
197  std::string shadernodename = std::string("ShaderNode for mesh " + _name.toUtf8());
198  shaderNode_->name(shadernodename);
199 
200  std::string texturenodename = std::string("TextureNode for mesh " + _name.toUtf8());
201  textureNode_->name(texturenodename);
202 }
203 
204 // ===============================================================================
205 // Content
206 // ===============================================================================
207 
211 template<class MeshT>
213  return mesh_.get();
214 }
215 
216 template<class MeshT>
217 const MeshT* VolumeMeshObject<MeshT>::mesh() const {
218  return mesh_.get();
219 }
220 
225 template<class MeshT>
227 
228  // No update necessary if no gui
229  if(OpenFlipper::Options::nogui())
230  return;
231 
233 
234  if(_type.contains(UPDATE_ALL) || _type.contains(UPDATE_TOPOLOGY)) {
235  updateGeometry();
236  updateColor();
237  updateTopology();
238  updateSelection();
239  } else {
240  if(_type.contains(UPDATE_GEOMETRY)) {
241  updateGeometry();
242  }
243  if(_type.contains(UPDATE_SELECTION)) {
244  updateSelection();
245  }
246  if(_type.contains(UPDATE_COLOR)) {
247  updateColor();
248  }
249  if (_type.contains(UPDATE_TEXTURE)){
250  updateTexture();
251  }
252  }
253 }
254 
256 template<class MeshT>
258 
259  if(meshNode_) {
260  meshNode_->set_selection_changed(true);
261  }
262 }
263 
265 template<class MeshT>
267 
269 
270  if(meshNode_) {
271  meshNode_->set_geometry_changed(true);
272  }
273 }
274 
276 template<class MeshT>
278 
279  if(meshNode_)
280  meshNode_->set_color_changed(true);
281 }
282 
284 template<class MeshT>
286 {
287  if(meshNode_)
288  meshNode_->set_texture_changed(true);
289 
290 }
291 
293 template<class MeshT>
295  if(meshNode_) {
296  meshNode_->set_topology_changed(true);
297  }
298 }
299 
300 template<class MeshT>
303  return static_cast<BaseObject*> (object);
304 }
305 
306 template<class MeshT>
308 {
309  return shaderNode_;
310 }
311 
312 template<class MeshT>
314 {
315  return textureNode_;
316 }
317 
318 // ===============================================================================
319 // Visualization
320 // ===============================================================================
324 template<class MeshT>
326  return meshNode_;
327 }
328 
331 template<class MeshT>
333  if(meshNode_) {
334  _bbMin = ACG::Vec3d(FLT_MAX, FLT_MAX, FLT_MAX);
335  _bbMax = ACG::Vec3d(-FLT_MAX, -FLT_MAX, -FLT_MAX);
336  meshNode_->boundingBox(_bbMin, _bbMax);
337  } else {
338  std::cerr << "Error: Bounding box computation via Scenegraph not available without gui." << std::endl;
339  }
340 }
341 
342 // ===============================================================================
343 // Object information
344 // ===============================================================================
345 
351 template<class MeshT>
353  QString output;
354 
355  output += "========================================================================\n";
356  output += BaseObjectData::getObjectinfo();
357 
358  if(dataType(typeId("PolyhedralMesh")))
359  output += "Object Contains Polyhedral Mesh : ";
360 
361  if(dataType(typeId("HexahedralMesh")))
362  output += "Object Contains Hexahedral Mesh : ";
363 
364  output += QString::number(mesh()->n_vertices()) + " vertices\n";
365  output += QString::number(mesh()->n_edges()) += " edges\n";
366  output += QString::number(mesh()->n_halfedges()) += " half-edges\n";
367  output += QString::number(mesh()->n_faces()) += " faces\n";
368  output += QString::number(mesh()->n_halffaces()) += " half-faces\n";
369  output += QString::number(mesh()->n_cells()) += " cells\n";
370 
371  output += "========================================================================\n";
372  return output;
373 }
374 
375 // ===============================================================================
376 // Picking
377 // ===============================================================================
378 
385 template<class MeshT>
386 bool VolumeMeshObject<MeshT>::picked(unsigned int _node_idx) {
387  return (_node_idx == meshNode_->id());
388 }
389 
390 template<class MeshT>
392  if(OpenFlipper::Options::nogui())
393  return;
394 
395  meshNode_->enablePicking(_enable);
396  shaderNode_->enablePicking(_enable);
397 }
398 
399 template<class MeshT>
401  return meshNode_->pickingEnabled();
402 }
403 
404 //=============================================================================
405 
406 template<class MeshT>
407 BaseNode*
409  return boundingBoxNode();
410 }
411 
412 //=============================================================================
virtual QString getObjectinfo()
Get all Info for the Object as a string.
Definition: BaseObject.cc:244
const UpdateType UPDATE_GEOMETRY(UpdateTypeSet(1)<< 2)
Geometry updated.
void deleteData()
Delete all data attached to this object ( calls delete on each object )
Definition: BaseObject.cc:812
bool pickingEnabled()
Check if picking is enabled for this Node.
VolumeMeshObject(const VolumeMeshObject &_object)
copy constructor
virtual void cleanup()
Reset current object, including all related nodes.
virtual void setName(QString _name) override
path to the file from which the object is loaded ( defaults to "." )
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
void enablePicking(bool _enable)
Enable or disable picking for this Node.
void updateTopology()
Update Topology of all data structures.
Namespace providing different geometric functions concerning angles.
ACG::SceneGraph::TextureNode * textureNode_
Scenegraph Texture Node.
void updateGeometry()
Update Geometry of all data structures.
ACG::SceneGraph::TextureNode * textureNode()
Return pointer to the texture node.
STL namespace.
QString getObjectinfo()
Get all Info for the Object as a string.
const UpdateType UPDATE_SELECTION(UpdateTypeSet(1)<< 4)
Selection updated.
TexCoordAttrib texcoordAttrib_
return a pointer to the mesh
This class provides easy access to DrawModes supported by OpenVolumeMesh.
Predefined datatypes.
Definition: DataTypes.hh:83
virtual void update(UpdateType _type=UPDATE_ALL)
Update the whole Object (Selection,Topology,...)
ACG::SceneGraph::VolumeMeshNodeT< MeshT > * meshNode_
Scenegraph Mesh Node.
QtTranslationManipulatorNode * manipulatorNode()
StatusAttrib statusAttrib_
return a pointer to the mesh
void boundingBox(ACG::Vec3d &_bbMin, typename ACG::Vec3d &_bbMax)
Get the BoundingBox of this object.
virtual void cleanup() override
void updateSelection()
Call this function to update the selection.
BoundingBoxNode * boundingBoxNode()
get a pointer to the bounding box node
ACG::SceneGraph::ShaderNode * shaderNode_
Scenegraph Shader Node.
virtual void init()
Initialise current object, including all related nodes.
NormalAttrib normalAttrib_
return a pointer to the mesh
void updateColor()
Update Colors of all data structures.
bool picked(unsigned int _node_idx)
detect if the node has been picked
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:730
Update type class.
Definition: UpdateType.hh:60
const UpdateType UPDATE_TEXTURE(UpdateTypeSet(1)<< 11)
Textures have changed.
MaterialNode * materialNode()
get a pointer to the materialnode
bool contains(const UpdateType &_type) const
Check if this update contains the given UpdateType.
Definition: UpdateType.cc:104
ACG::SceneGraph::VolumeMeshNodeT< MeshT > * meshNode()
Get the Scenegraph Mesh Node.
const UpdateType UPDATE_TOPOLOGY(UpdateTypeSet(1)<< 3)
Topology updated.
void boundingBox(Vec3d &_bbMin, Vec3d &_bbMax) override
update bounding box
MeshT * mesh()
return a pointer to the mesh
BaseNode * primaryNode()
Scenegraph Mesh Node.
ACG::SceneGraph::ShaderNode * shaderNode()
Return pointer to the shader node.
void setMainGLContext()
Set current GL Context to main context.
void update_face_normals()
Compute face normals.
ptr::shared_ptr< MeshT > mesh_
return a pointer to the mesh
ColorAttrib colorAttrib_
return a pointer to the mesh
std::string name() const
Returns: name of node (needs not be unique)
void setDataType(DataType _type)
Definition: BaseObject.cc:233
virtual ~VolumeMeshObject()
destructor
ACG::SceneGraph::ShaderNode ShaderNode
Simple Name for ShaderNode.
DataType dataType() const
Definition: BaseObject.cc:229
void set_point_size(float _sz)
set point size (default: 1.0)
void updateTexture()
Update Texture of all data structures.
const UpdateType UPDATE_COLOR(UpdateTypeSet(1)<< 10)
Colors have changed.
DLLEXPORT DataType typeId(QString _name)
Given a dataType Identifier string this function will return the id of the datatype.
Definition: Types.cc:139
VectorT< double, 3 > Vec3d
Definition: VectorT.hh:121
void setName(QString _name)
Set the name of the Object.