43 #ifdef ENABLE_SPLATCLOUD_SUPPORT
49 #include "PoissonReconstructionPlugin.hh"
59 #include "PoissonReconstructionT.hh"
61 PoissonPlugin::PoissonPlugin() :
68 void PoissonPlugin::initializePlugin(){
70 if ( ! OpenFlipper::Options::gui())
77 toolIcon_ =
new QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"PoissonReconstruction.png");
78 emit addToolbox( tr(
"Poisson Reconstruction") , tool_, toolIcon_);
81 "This plugin is based on the code published by Michael Kazhdan and Matthew Bolitho<br> "
83 "The following license applies to their code: <br> "
84 "Copyright (c) 2006, Michael Kazhdan and Matthew Bolitho <br> "
85 "All rights reserved. <br> "
87 "Redistribution and use in source and binary forms, with or without modification, "
88 "are permitted provided that the following conditions are met: <br> "
90 "Redistributions of source code must retain the above copyright notice, this list of "
91 "conditions and the following disclaimer. Redistributions in binary form must reproduce "
92 "the above copyright notice, this list of conditions and the following disclaimer "
93 "in the documentation and/or other materials provided with the distribution. <br> "
95 "Neither the name of the Johns Hopkins University nor the names of its contributors "
96 "may be used to endorse or promote products derived from this software without specific "
97 "prior written permission. <br> "
99 "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY "
100 "EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES "
101 "OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT "
102 "SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, "
103 "INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED "
104 "TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR "
105 "BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN "
106 "CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN "
107 "ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH "
110 emit addAboutInfo(info,
"Poisson Reconstruction Plugin");
113 tool_->reconstructButton->setWhatsThis(tool_->reconstructButton->toolTip()+whatGen.generateLink());
114 tool_->depthBox->setWhatsThis(tool_->depthBox->toolTip()+whatGen.generateLink(
"octree"));
115 tool_->label->setWhatsThis(tool_->label->toolTip()+whatGen.generateLink(
"octree"));
119 void PoissonPlugin::pluginsInitialized()
121 emit setSlotDescription(
"poissonReconstruct(int,int)",tr(
"Reconstruct a triangle mesh from the given object. Returns the id of the new object or -1 if it failed."),
122 QStringList(tr(
"ObjectId;depth").split(
';')),QStringList(tr(
"ObjectId of the object;octree depth").split(
';')));
123 emit setSlotDescription(
"poissonReconstruct(IdList,int)",tr(
"Reconstruct one triangle mesh from the given objects. Returns the id of the new object or -1 if it failed."),
124 QStringList(tr(
"IdList;depth").split(
';')),QStringList(tr(
"Id of the objects;octree depth").split(
';')));
126 emit setSlotDescription(
"poissonReconstruct(int)",tr(
"Reconstruct a triangle mesh from the given object. (Octree depth defaults to 7). Returns the id of the new object or -1 if it failed."),
127 QStringList(tr(
"ObjectId")),QStringList(tr(
"ObjectId of the object")));
128 emit setSlotDescription(
"poissonReconstruct(IdList)",tr(
"Reconstruct one triangle mesh from the given objects. (Octree depth defaults to 7). Returns the id of the new object or -1 if it failed."),
129 QStringList(tr(
"IdList")),QStringList(tr(
"Id of the objects")));
132 int PoissonPlugin::poissonReconstruct(
int _id,
int _depth)
135 return poissonReconstruct(list, _depth);
138 int PoissonPlugin::poissonReconstruct(
IdList _ids,
int _depth)
142 unsigned int n_points = 0;
146 std::vector< Real > pt_data;
149 for (IdList::iterator idIter = _ids.begin(); idIter != _ids.end(); ++idIter)
154 emit log(
LOGERR , QString(
"Unable to get Object width id %1").arg(*idIter));
164 n_points += mesh->n_vertices();
166 emit log(
LOGINFO,QString(
"Adding %1 points from Object %2").arg(mesh->n_vertices()).arg(*idIter) );
168 pt_data.reserve( n_points * 6 );
169 TriMesh::VertexIter vit = mesh->vertices_begin();
170 for ( ; vit != mesh->vertices_end(); ++vit )
172 pt_data.push_back( mesh->point( *vit )[0] );
173 pt_data.push_back( mesh->point( *vit )[1] );
174 pt_data.push_back( mesh->point( *vit )[2] );
175 pt_data.push_back( mesh->normal( *vit )[0] );
176 pt_data.push_back( mesh->normal( *vit )[1] );
177 pt_data.push_back( mesh->normal( *vit )[2] );
185 n_points += mesh->n_vertices();
187 emit log(
LOGINFO,QString(
"Adding %1 points from Object %2").arg(mesh->n_vertices()).arg(*idIter) );
189 pt_data.reserve( n_points * 6 );
190 PolyMesh::VertexIter vit = mesh->vertices_begin();
191 for ( ; vit != mesh->vertices_end(); ++vit )
193 pt_data.push_back( mesh->point( *vit )[0] );
194 pt_data.push_back( mesh->point( *vit )[1] );
195 pt_data.push_back( mesh->point( *vit )[2] );
196 pt_data.push_back( mesh->normal( *vit )[0] );
197 pt_data.push_back( mesh->normal( *vit )[1] );
198 pt_data.push_back( mesh->normal( *vit )[2] );
202 #ifdef ENABLE_SPLATCLOUD_SUPPORT
210 emit log(
LOGERR,
"Splat cloud has no normals. Skipping it");
216 emit log(
LOGINFO,QString(
"Adding %1 points from Object %2").arg(cloud->
numSplats()).arg(*idIter) );
218 pt_data.reserve( n_points * 6 );
219 for (
unsigned i = 0 ; i < cloud->
numSplats(); ++i )
221 pt_data.push_back( cloud->
positions( i )[0] );
222 pt_data.push_back( cloud->
positions( i )[1] );
223 pt_data.push_back( cloud->
positions( i )[2] );
224 pt_data.push_back( cloud->
normals( i )[0] );
225 pt_data.push_back( cloud->
normals( i )[1] );
226 pt_data.push_back( cloud->
normals( i )[2] );
231 emit log(
LOGERR,QString(
"ObjectType of Object with id %1 is unsupported").arg(*idIter));
238 if ( !pt_data.empty() ) {
240 emit log(
LOGINFO,
"Creating Object");
257 params.Depth = _depth;
259 emit log(
LOGINFO,
"Starting reconstruction");
261 if ( pr.run( pt_data, *final_mesh, params ) ) {
262 emit log(
LOGINFO,
"Reconstruction succeeded");
264 finalObject->
setName(
"Poisson Reconstruction.obj");
266 emit log(
LOGERR,
"Reconstruction failed");
267 emit deleteObject( meshId );
279 if ( ! OpenFlipper::Options::gui())
286 #ifdef ENABLE_SPLATCLOUD_SUPPORT
292 ids.push_back(o_it->id());
293 std::cerr <<
"Added " << o_it->id() << std::endl;
296 const int depth = tool_->depthBox->value();
298 poissonReconstruct(ids,depth);
302 #if QT_VERSION < 0x050000
std::vector< int > IdList
Standard Type for id Lists used for scripting.
bool dataType(DataType _type) const
bool getMesh(int _identifier, PolyMesh *&_mesh)
Get the Poly Mesh which has the given identifier.
TriMesh * triMesh(BaseObjectData *_object)
Get a triangle mesh from an object.
void setName(QString _name)
Set the name of the Object.
bool getObject(int _identifier, BSplineCurveObject *&_object)
PolyMesh * polyMesh(BaseObjectData *_object)
Get a poly mesh from an object.
Type for a MeshObject containing a triangle mesh.
Normal & normals(int _idx)
Get a reference of the predefined property's value.
void slotPoissonReconstruct()
Button slot iterating over all targets and passing them to the correct functions. ...
virtual void updatedObject(int _objectId)
An object has been changed or added by this plugin.
#define DATA_TRIANGLE_MESH
TriMeshObject * triMeshObject(BaseObjectData *_object)
Cast an BaseObject to a TriMeshObject if possible.
bool hasNormals() const
Return the availability of the predefined property.
unsigned int numSplats() const
Get the number of splats.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
Position & positions(int _idx)
Get a reference of the predefined property's value.
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
a class which provides an link generator for WhatsThisMessages linking to the user doc If you have an...
const QStringList TARGET_OBJECTS("target")
Iterable object range.
SplatCloud * splatCloud(BaseObjectData *_object)
Get a SplatCloud from an object.