FeatureMeshDefects.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2006 Werner Mayer <wmayer[at]users.sourceforge.net>     *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 
00024 
00025 #include "PreCompiled.h"
00026 
00027 #ifndef _PreComp_
00028 #endif
00029 
00030 #include "FeatureMeshDefects.h"
00031 #include "Core/Degeneration.h"
00032 #include "Core/TopoAlgorithm.h"
00033 #include "Core/Triangulation.h"
00034 
00035 using namespace Mesh;
00036 
00037 
00038 //===========================================================================
00039 // Defects Feature
00040 //===========================================================================
00041 
00042 PROPERTY_SOURCE(Mesh::FixDefects, Mesh::Feature)
00043 
00044 FixDefects::FixDefects()
00045 {
00046   ADD_PROPERTY(Source  ,(0));
00047 }
00048 
00049 FixDefects::~FixDefects()
00050 {
00051 }
00052 
00053 short FixDefects::mustExecute() const
00054 {
00055     if (Source.isTouched())
00056         return 1;
00057     return 0;
00058 }
00059 
00060 App::DocumentObjectExecReturn *FixDefects::execute(void)
00061 {
00062   return App::DocumentObject::StdReturn;
00063 }
00064 
00065 // ----------------------------------------------------------------------
00066 
00067 PROPERTY_SOURCE(Mesh::HarmonizeNormals, Mesh::FixDefects)
00068 
00069 HarmonizeNormals::HarmonizeNormals()
00070 {
00071 }
00072 
00073 HarmonizeNormals::~HarmonizeNormals()
00074 {
00075 }
00076 
00077 App::DocumentObjectExecReturn *HarmonizeNormals::execute(void)
00078 {
00079     App::DocumentObject* link = Source.getValue();
00080     if (!link) return new App::DocumentObjectExecReturn("No mesh linked");
00081     App::Property* prop = link->getPropertyByName("Mesh");
00082     if (prop && prop->getTypeId() == Mesh::PropertyMeshKernel::getClassTypeId()) {
00083         Mesh::PropertyMeshKernel* kernel = static_cast<Mesh::PropertyMeshKernel*>(prop);
00084         std::auto_ptr<MeshObject> mesh(new MeshObject);
00085         *mesh = kernel->getValue();
00086         mesh->harmonizeNormals();
00087         this->Mesh.setValuePtr(mesh.release());
00088     }
00089 
00090     return App::DocumentObject::StdReturn;
00091 }
00092 
00093 // ----------------------------------------------------------------------
00094 
00095 PROPERTY_SOURCE(Mesh::FlipNormals, Mesh::FixDefects)
00096 
00097 FlipNormals::FlipNormals()
00098 {
00099 }
00100 
00101 FlipNormals::~FlipNormals()
00102 {
00103 }
00104 
00105 App::DocumentObjectExecReturn *FlipNormals::execute(void)
00106 {
00107     App::DocumentObject* link = Source.getValue();
00108     if (!link) return new App::DocumentObjectExecReturn("No mesh linked");
00109     App::Property* prop = link->getPropertyByName("Mesh");
00110     if (prop && prop->getTypeId() == Mesh::PropertyMeshKernel::getClassTypeId()) {
00111         Mesh::PropertyMeshKernel* kernel = static_cast<Mesh::PropertyMeshKernel*>(prop);
00112         std::auto_ptr<MeshObject> mesh(new MeshObject);
00113         *mesh = kernel->getValue();
00114         mesh->flipNormals();
00115         this->Mesh.setValuePtr(mesh.release());
00116     }
00117 
00118     return App::DocumentObject::StdReturn;
00119 }
00120 
00121 // ----------------------------------------------------------------------
00122 
00123 PROPERTY_SOURCE(Mesh::FixNonManifolds, Mesh::FixDefects)
00124 
00125 FixNonManifolds::FixNonManifolds()
00126 {
00127 }
00128 
00129 FixNonManifolds::~FixNonManifolds()
00130 {
00131 }
00132 
00133 App::DocumentObjectExecReturn *FixNonManifolds::execute(void)
00134 {
00135     App::DocumentObject* link = Source.getValue();
00136     if (!link) return new App::DocumentObjectExecReturn("No mesh linked");
00137     App::Property* prop = link->getPropertyByName("Mesh");
00138     if (prop && prop->getTypeId() == Mesh::PropertyMeshKernel::getClassTypeId()) {
00139         Mesh::PropertyMeshKernel* kernel = static_cast<Mesh::PropertyMeshKernel*>(prop);
00140         std::auto_ptr<MeshObject> mesh(new MeshObject);
00141         *mesh = kernel->getValue();
00142         mesh->removeNonManifolds();
00143         this->Mesh.setValuePtr(mesh.release());
00144     }
00145 
00146     return App::DocumentObject::StdReturn;
00147 }
00148 
00149 // ----------------------------------------------------------------------
00150 
00151 PROPERTY_SOURCE(Mesh::FixDuplicatedFaces, Mesh::FixDefects)
00152 
00153 FixDuplicatedFaces::FixDuplicatedFaces()
00154 {
00155 }
00156 
00157 FixDuplicatedFaces::~FixDuplicatedFaces()
00158 {
00159 }
00160 
00161 App::DocumentObjectExecReturn *FixDuplicatedFaces::execute(void)
00162 {
00163     App::DocumentObject* link = Source.getValue();
00164     if (!link) return new App::DocumentObjectExecReturn("No mesh linked");
00165     App::Property* prop = link->getPropertyByName("Mesh");
00166     if (prop && prop->getTypeId() == Mesh::PropertyMeshKernel::getClassTypeId()) {
00167         Mesh::PropertyMeshKernel* kernel = static_cast<Mesh::PropertyMeshKernel*>(prop);
00168         std::auto_ptr<MeshObject> mesh(new MeshObject);
00169         *mesh = kernel->getValue();
00170         mesh->removeDuplicatedFacets();
00171         this->Mesh.setValuePtr(mesh.release());
00172     }
00173 
00174     return App::DocumentObject::StdReturn;
00175 }
00176 
00177 // ----------------------------------------------------------------------
00178 
00179 PROPERTY_SOURCE(Mesh::FixDuplicatedPoints, Mesh::FixDefects)
00180 
00181 FixDuplicatedPoints::FixDuplicatedPoints()
00182 {
00183 }
00184 
00185 FixDuplicatedPoints::~FixDuplicatedPoints()
00186 {
00187 }
00188 
00189 App::DocumentObjectExecReturn *FixDuplicatedPoints::execute(void)
00190 {
00191     App::DocumentObject* link = Source.getValue();
00192     if (!link) return new App::DocumentObjectExecReturn("No mesh linked");
00193     App::Property* prop = link->getPropertyByName("Mesh");
00194     if (prop && prop->getTypeId() == Mesh::PropertyMeshKernel::getClassTypeId()) {
00195         Mesh::PropertyMeshKernel* kernel = static_cast<Mesh::PropertyMeshKernel*>(prop);
00196         std::auto_ptr<MeshObject> mesh(new MeshObject);
00197         *mesh = kernel->getValue();
00198         mesh->removeDuplicatedPoints();
00199         this->Mesh.setValuePtr(mesh.release());
00200     }
00201 
00202     return App::DocumentObject::StdReturn;
00203 }
00204 
00205 // ----------------------------------------------------------------------
00206 
00207 PROPERTY_SOURCE(Mesh::FixDegenerations, Mesh::FixDefects)
00208 
00209 FixDegenerations::FixDegenerations()
00210 {
00211 }
00212 
00213 FixDegenerations::~FixDegenerations()
00214 {
00215 }
00216 
00217 App::DocumentObjectExecReturn *FixDegenerations::execute(void)
00218 {
00219     App::DocumentObject* link = Source.getValue();
00220     if (!link) return new App::DocumentObjectExecReturn("No mesh linked");
00221     App::Property* prop = link->getPropertyByName("Mesh");
00222     if (prop && prop->getTypeId() == Mesh::PropertyMeshKernel::getClassTypeId()) {
00223         Mesh::PropertyMeshKernel* kernel = static_cast<Mesh::PropertyMeshKernel*>(prop);
00224         std::auto_ptr<MeshObject> mesh(new MeshObject);
00225         *mesh = kernel->getValue();
00226         mesh->validateDegenerations();
00227         this->Mesh.setValuePtr(mesh.release());
00228     }
00229 
00230     return App::DocumentObject::StdReturn;
00231 }
00232 
00233 // ----------------------------------------------------------------------
00234 
00235 PROPERTY_SOURCE(Mesh::FixDeformations, Mesh::FixDefects)
00236 
00237 FixDeformations::FixDeformations()
00238 {
00239   ADD_PROPERTY(MaxAngle  ,(0.1f));
00240 }
00241 
00242 FixDeformations::~FixDeformations()
00243 {
00244 }
00245 
00246 App::DocumentObjectExecReturn *FixDeformations::execute(void)
00247 {
00248     App::DocumentObject* link = Source.getValue();
00249     if (!link) return new App::DocumentObjectExecReturn("No mesh linked");
00250     App::Property* prop = link->getPropertyByName("Mesh");
00251     if (prop && prop->getTypeId() == Mesh::PropertyMeshKernel::getClassTypeId()) {
00252         Mesh::PropertyMeshKernel* kernel = static_cast<Mesh::PropertyMeshKernel*>(prop);
00253         std::auto_ptr<MeshObject> mesh(new MeshObject);
00254         *mesh = kernel->getValue();
00255         mesh->validateDeformations(MaxAngle.getValue());
00256         this->Mesh.setValuePtr(mesh.release());
00257     }
00258 
00259     return App::DocumentObject::StdReturn;
00260 }
00261 
00262 // ----------------------------------------------------------------------
00263 
00264 PROPERTY_SOURCE(Mesh::FixIndices, Mesh::FixDefects)
00265 
00266 FixIndices::FixIndices()
00267 {
00268 }
00269 
00270 FixIndices::~FixIndices()
00271 {
00272 }
00273 
00274 App::DocumentObjectExecReturn *FixIndices::execute(void)
00275 {
00276     App::DocumentObject* link = Source.getValue();
00277     if (!link) return new App::DocumentObjectExecReturn("No mesh linked");
00278     App::Property* prop = link->getPropertyByName("Mesh");
00279     if (prop && prop->getTypeId() == Mesh::PropertyMeshKernel::getClassTypeId()) {
00280         Mesh::PropertyMeshKernel* kernel = static_cast<Mesh::PropertyMeshKernel*>(prop);
00281         std::auto_ptr<MeshObject> mesh(new MeshObject);
00282         *mesh = kernel->getValue();
00283         mesh->validateIndices();
00284         this->Mesh.setValuePtr(mesh.release());
00285     }
00286 
00287     return App::DocumentObject::StdReturn;
00288 }
00289 
00290 // ----------------------------------------------------------------------
00291 
00292 PROPERTY_SOURCE(Mesh::FillHoles, Mesh::FixDefects)
00293 
00294 FillHoles::FillHoles()
00295 {
00296     ADD_PROPERTY(FillupHolesOfLength,(0));
00297     ADD_PROPERTY(MaxArea,(0.1f));
00298 }
00299 
00300 FillHoles::~FillHoles()
00301 {
00302 }
00303 
00304 App::DocumentObjectExecReturn *FillHoles::execute(void)
00305 {
00306     App::DocumentObject* link = Source.getValue();
00307     if (!link) return new App::DocumentObjectExecReturn("No mesh linked");
00308     App::Property* prop = link->getPropertyByName("Mesh");
00309     if (prop && prop->getTypeId() == Mesh::PropertyMeshKernel::getClassTypeId()) {
00310         Mesh::PropertyMeshKernel* kernel = static_cast<Mesh::PropertyMeshKernel*>(prop);
00311         std::auto_ptr<MeshObject> mesh(new MeshObject);
00312         *mesh = kernel->getValue();
00313         MeshCore::ConstraintDelaunayTriangulator cTria(MaxArea.getValue());
00314         //MeshCore::Triangulator cTria(mesh->getKernel());
00315         mesh->fillupHoles(FillupHolesOfLength.getValue(), 1, cTria);
00316         this->Mesh.setValuePtr(mesh.release());
00317     }
00318 
00319     return App::DocumentObject::StdReturn;
00320 }
00321 
00322 // ----------------------------------------------------------------------
00323 
00324 PROPERTY_SOURCE(Mesh::RemoveComponents, Mesh::FixDefects)
00325 
00326 RemoveComponents::RemoveComponents()
00327 {
00328     ADD_PROPERTY(RemoveCompOfSize,(0));
00329 }
00330 
00331 RemoveComponents::~RemoveComponents()
00332 {
00333 }
00334 
00335 App::DocumentObjectExecReturn *RemoveComponents::execute(void)
00336 {
00337     App::DocumentObject* link = Source.getValue();
00338     if (!link) return new App::DocumentObjectExecReturn("No mesh linked");
00339     App::Property* prop = link->getPropertyByName("Mesh");
00340     if (prop && prop->getTypeId() == Mesh::PropertyMeshKernel::getClassTypeId()) {
00341         Mesh::PropertyMeshKernel* kernel = static_cast<Mesh::PropertyMeshKernel*>(prop);
00342         std::auto_ptr<MeshObject> mesh(new MeshObject);
00343         *mesh = kernel->getValue();
00344         mesh->removeComponents(RemoveCompOfSize.getValue());
00345         this->Mesh.setValuePtr(mesh.release());
00346     }
00347 
00348     return App::DocumentObject::StdReturn;
00349 }

Generated on Wed Nov 23 19:00:11 2011 for FreeCAD by  doxygen 1.6.1