Developer Documentation
Loading...
Searching...
No Matches
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
68template<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
85template<class MeshT>
87 BaseObjectData(), mesh_(new MeshT()),
88 statusAttrib_(*mesh_),
89 colorAttrib_(*mesh_, ACG::Vec4f(1.0f, 1.0f, 1.0f, 1.0f) /* Default color */),
90 normalAttrib_(*mesh_),
91 texcoordAttrib_(*mesh_),
92 meshNode_(NULL),
93 shaderNode_(NULL),
94 textureNode_(NULL)
95{
96
97 setDataType(_typeId);
98 init();
99}
100
101
102template<class MeshT>
104{
105 statusAttrib_ = StatusAttrib(*mesh_);
106 colorAttrib_ = ColorAttrib(*mesh_);
107 normalAttrib_ = NormalAttrib(*mesh_);
108 texcoordAttrib_ = TexCoordAttrib(*mesh_);
109}
110
111template<class MeshT>
113
114 // Delete the data attached to this object (this will remove all perObject data)
115 // Not the best way to do it but it will work.
116 // This is only necessary if people use references to the mesh below and
117 // they do something with the mesh in the destructor of their
118 // perObjectData.
119 deleteData();
120
121 // No need to delete the scenegraph nodes as this will be managed by baseplugin
122 meshNode_ = 0;
123 shaderNode_ = 0;
124 textureNode_ = 0;
125}
126
130template<class MeshT>
132
134
135 meshNode_ = 0;
136 shaderNode_ = 0;
137 textureNode_ = 0;
138
139 init();
140}
141
145template<class MeshT>
147
148 // Only initialize scenegraph nodes when we initialized a gui!!
149 if(OpenFlipper::Options::nogui())
150 return;
151
152 VolumeMeshDrawModesContainer drawModes; // create this object before initializing the textureNode
153
154 textureNode_ = new ACG::SceneGraph::TextureNode(materialNode() , "NEW TextureNode for ");
155
156 shaderNode_ = new ACG::SceneGraph::ShaderNode(textureNode_ , "NEW ShaderNode for ");
157
158 meshNode_ = new ACG::SceneGraph::VolumeMeshNodeT<MeshT>(*mesh_, statusAttrib_, colorAttrib_, normalAttrib_, texcoordAttrib_, materialNode(), shaderNode_, "NEW VolumeMeshNode");
159
160 if(manipulatorNode() == NULL)
161 std::cerr << "Error when creating volume mesh object! Manipulator node is NULL!" << std::endl;
162
163 if(materialNode() == NULL)
164 std::cerr << "Error when creating mesh object! Material node is NULL!" << std::endl;
165
166 materialNode()->set_point_size(12.0f);
167
168 QString shaderDir = OpenFlipper::Options::shaderDirStr() + OpenFlipper::Options::dirSeparator();
169
170 std::string shaderDirectory = std::string( shaderDir.toUtf8() );
171 shaderNode_->setShaderDir( shaderDirectory );
172
173 if(!OpenFlipper::Options::coreProfile())
174 {
175 if ( QFile( shaderDir + "Phong/Vertex.glsl").exists() && QFile( shaderDir + "Phong/Fragment.glsl" ).exists() )
176 {
177 shaderNode_->setShader(drawModes.cellsPhongShaded, "Phong/Vertex.glsl" , "Phong/Fragment.glsl" );
178 shaderNode_->setShader(drawModes.facesPhongShaded, "Phong/Vertex.glsl" , "Phong/Fragment.glsl" );
179 shaderNode_->setShader(drawModes.halffacesPhongShaded,"Phong/Vertex.glsl" , "Phong/Fragment.glsl" );
180 }
181 else
182 std::cerr << "Shader Files for Phong not found!" << std::endl;
183 }
184
185 // Update all nodes
186 update();
187}
188
189// ===============================================================================
190// Name/Path Handling
191// ===============================================================================
192
196template<class MeshT>
199
200 // No update when gui is not active
201 if(OpenFlipper::Options::nogui())
202 return;
203
204 std::string meshnodename = std::string("VolumeMeshNode for mesh " + _name.toUtf8());
205 meshNode_->name(meshnodename);
206
207 std::string shadernodename = std::string("ShaderNode for mesh " + _name.toUtf8());
208 shaderNode_->name(shadernodename);
209
210 std::string texturenodename = std::string("TextureNode for mesh " + _name.toUtf8());
211 textureNode_->name(texturenodename);
212}
213
214// ===============================================================================
215// Content
216// ===============================================================================
217
221template<class MeshT>
223 return mesh_.get();
224}
225
226template<class MeshT>
228 return mesh_.get();
229}
230
235template<class MeshT>
237
238 // No update necessary if no gui
239 if(OpenFlipper::Options::nogui())
240 return;
241
243
244 if(_type.contains(UPDATE_ALL) || _type.contains(UPDATE_TOPOLOGY)) {
245 updateGeometry();
246 updateColor();
247 updateTopology();
248 updateSelection();
249 } else {
250 if(_type.contains(UPDATE_GEOMETRY)) {
251 updateGeometry();
252 }
253 if(_type.contains(UPDATE_SELECTION)) {
254 updateSelection();
255 }
256 if(_type.contains(UPDATE_COLOR)) {
257 updateColor();
258 }
259 if (_type.contains(UPDATE_TEXTURE)){
260 updateTexture();
261 }
262 }
263}
264
266template<class MeshT>
268
269 if(meshNode_) {
270 meshNode_->set_selection_changed(true);
271 }
272}
273
275template<class MeshT>
277
278 normalAttrib_.update_face_normals();
279
280 if(meshNode_) {
281 meshNode_->set_geometry_changed(true);
282 }
283}
284
286template<class MeshT>
288
289 if(meshNode_)
290 meshNode_->set_color_changed(true);
291}
292
294template<class MeshT>
296{
297 if(meshNode_)
298 meshNode_->set_texture_changed(true);
299
300}
301
303template<class MeshT>
305 if(meshNode_) {
306 meshNode_->set_topology_changed(true);
307 }
308}
309
310template<class MeshT>
313 return static_cast<BaseObject*> (object);
314}
315
316template<class MeshT>
321
322template<class MeshT>
327
328// ===============================================================================
329// Visualization
330// ===============================================================================
334template<class MeshT>
338
341template<class MeshT>
343 if(meshNode_) {
344 _bbMin = ACG::Vec3d(FLT_MAX, FLT_MAX, FLT_MAX);
345 _bbMax = ACG::Vec3d(-FLT_MAX, -FLT_MAX, -FLT_MAX);
346 meshNode_->boundingBox(_bbMin, _bbMax);
347 } else {
348 std::cerr << "Error: Bounding box computation via Scenegraph not available without gui." << std::endl;
349 }
350}
351
352// ===============================================================================
353// Object information
354// ===============================================================================
355
361template<class MeshT>
363 QString output;
364
365 output += "========================================================================\n";
367
368 if(dataType(typeId("PolyhedralMesh")))
369 output += "Object Contains Polyhedral Mesh : ";
370
371 if(dataType(typeId("HexahedralMesh")))
372 output += "Object Contains Hexahedral Mesh : ";
373
374 output += QString::number(mesh()->n_vertices()) + " vertices\n";
375 output += QString::number(mesh()->n_edges()) += " edges\n";
376 output += QString::number(mesh()->n_halfedges()) += " half-edges\n";
377 output += QString::number(mesh()->n_faces()) += " faces\n";
378 output += QString::number(mesh()->n_halffaces()) += " half-faces\n";
379 output += QString::number(mesh()->n_cells()) += " cells\n";
380
381 output += "========================================================================\n";
382 return output;
383}
384
385// ===============================================================================
386// Picking
387// ===============================================================================
388
395template<class MeshT>
396bool VolumeMeshObject<MeshT>::picked(unsigned int _node_idx) {
397 return (_node_idx == meshNode_->id());
398}
399
400template<class MeshT>
402 if(OpenFlipper::Options::nogui())
403 return;
404
405 meshNode_->enablePicking(_enable);
406 shaderNode_->enablePicking(_enable);
407}
408
409template<class MeshT>
411 return meshNode_->pickingEnabled();
412}
413
414//=============================================================================
415
416template<class MeshT>
419 return boundingBoxNode();
420}
421
422//=============================================================================
DLLEXPORT DataType typeId(QString _name)
Given a dataType Identifier string this function will return the id of the datatype.
Definition Types.cc:139
virtual void setName(QString _name) override
path to the file from which the object is loaded ( defaults to "." )
virtual void cleanup() override
virtual QString getObjectinfo()
Get all Info for the Object as a string.
QString name() const
return the name of the object. The name defaults to NONAME if unset.
void setDataType(DataType _type)
Predefined datatypes.
Definition DataTypes.hh:83
Update type class.
Definition UpdateType.hh:59
bool contains(const UpdateType &_type) const
Check if this update contains the given UpdateType.
Definition UpdateType.cc:99
This class provides easy access to DrawModes supported by OpenVolumeMesh.
virtual void update(UpdateType _type=UPDATE_ALL)
Update the whole Object (Selection,Topology,...)
bool pickingEnabled()
Check if picking is enabled for this Node.
QString getObjectinfo()
Get all Info for the Object as a string.
MeshT * mesh()
return a pointer to the mesh
virtual void cleanup()
Reset current object, including all related nodes.
ACG::SceneGraph::TextureNode * textureNode()
Return pointer to the texture node.
void updateGeometry()
Update Geometry of all data structures.
bool picked(unsigned int _node_idx)
detect if the node has been picked
virtual void init()
Initialise current object, including all related nodes.
VolumeMeshObject(const VolumeMeshObject &_object)
copy constructor
void updateColor()
Update Colors of all data structures.
void boundingBox(ACG::Vec3d &_bbMin, typename ACG::Vec3d &_bbMax)
Get the BoundingBox of this object.
BaseNode * primaryNode()
Scenegraph Mesh Node.
ACG::SceneGraph::ShaderNode * shaderNode()
Return pointer to the shader node.
ACG::SceneGraph::VolumeMeshNodeT< MeshT > * meshNode()
Get the Scenegraph Mesh Node.
void updateTopology()
Update Topology of all data structures.
void updateTexture()
Update Texture of all data structures.
void enablePicking(bool _enable)
Enable or disable picking for this Node.
void setName(QString _name)
Set the name of the Object.
void updateSelection()
Call this function to update the selection.
virtual ~VolumeMeshObject()
destructor
const UpdateType UPDATE_TEXTURE(UpdateTypeSet(2048))
Textures have changed.
const UpdateType UPDATE_TOPOLOGY(UpdateTypeSet(8))
Topology updated.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
const UpdateType UPDATE_GEOMETRY(UpdateTypeSet(4))
Geometry updated.
const UpdateType UPDATE_COLOR(UpdateTypeSet(1024))
Colors have changed.
const UpdateType UPDATE_SELECTION(UpdateTypeSet(16))
Selection updated.
Namespace providing different geometric functions concerning angles.
VectorT< double, 3 > Vec3d
Definition VectorT.hh:121
void setMainGLContext()
Set current GL Context to main context.