1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
|
//##########################################################################
//# #
//# CLOUDCOMPARE #
//# #
//# This program is free software; you can redistribute it and/or modify #
//# it under the terms of the GNU General Public License as published by #
//# the Free Software Foundation; version 2 or later of the License. #
//# #
//# This program is distributed in the hope that it will be useful, #
//# but WITHOUT ANY WARRANTY; without even the implied warranty of #
//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
//# GNU General Public License for more details. #
//# #
//# COPYRIGHT: EDF R&D / TELECOM ParisTech (ENST-TSI) #
//# #
//##########################################################################
#include "PDMSFilter.h"
#include "PdmsParser.h"
//qCC_db
#include <ccLog.h>
#include <ccMesh.h>
#include <ccPointCloud.h>
#include <ccCylinder.h>
#include <ccTorus.h>
#include <ccBox.h>
#include <ccCone.h>
#include <ccDish.h>
#include <ccExtru.h>
#include <assert.h>
using namespace CCLib;
bool PDMSFilter::canLoadExtension(const QString& upperCaseExt) const
{
return ( upperCaseExt == "MAC"
|| upperCaseExt == "PDMS"
|| upperCaseExt == "PDMSMAC" );
}
bool PDMSFilter::canSave(CC_CLASS_ENUM type, bool& multiple, bool& exclusive) const
{
//not supported yet
return false;
}
typedef std::pair<PdmsTools::PdmsObjects::GenericItem*, ccHObject*> PdmsAndCCPair;
CC_FILE_ERROR PDMSFilter::loadFile(const QString& filename, ccHObject& container, LoadParameters& parameters)
{
PdmsParser parser;
PdmsFileSession session(qPrintable(filename)); //DGM: warning, toStdString doesn't preserve "local" characters
parser.linkWithSession(&session);
if (parser.parseSessionContent())
{
PdmsTools::PdmsObjects::GenericItem* pdmsmodel = parser.getLoadedObject(true);
assert(pdmsmodel);
std::vector< PdmsAndCCPair > treeSync;
treeSync.push_back(PdmsAndCCPair(pdmsmodel,&container));
while (!treeSync.empty())
{
PdmsAndCCPair currentPair = treeSync.back();
treeSync.pop_back();
if (currentPair.first->isGroupElement())
{
PdmsTools::PdmsObjects::GroupElement* group = static_cast<PdmsTools::PdmsObjects::GroupElement*>(currentPair.first);
//primitives
{
for (std::list<PdmsTools::PdmsObjects::DesignElement*>::const_iterator it = group->elements.begin(); it != group->elements.end(); ++it)
treeSync.push_back(PdmsAndCCPair(*it, currentPair.second));
}
//sub-groups
{
for (std::list<PdmsTools::PdmsObjects::GroupElement*>::const_iterator it = group->subhierarchy.begin(); it != group->subhierarchy.end(); ++it)
{
ccHObject* subGroup = new ccHObject((*it)->name);
currentPair.second->addChild(subGroup);
treeSync.push_back(PdmsAndCCPair(*it, subGroup));
}
}
}
else
{
//Convert PDMS GenericItem to the corresponding ccHObject
ccMesh* primitive = 0;
QString unsupportedPrimitiveStr("unknown");
switch (currentPair.first->getType())
{
case PDMS_SCYLINDER:
{
PdmsTools::PdmsObjects::SCylinder* pdmsCyl = static_cast<PdmsTools::PdmsObjects::SCylinder*>(currentPair.first);
primitive = new ccCylinder(pdmsCyl->diameter / 2, pdmsCyl->height, 0, pdmsCyl->name);
}
break;
case PDMS_CTORUS:
{
PdmsTools::PdmsObjects::CTorus* pdmsCTor = static_cast<PdmsTools::PdmsObjects::CTorus*>(currentPair.first);
primitive = new ccTorus(pdmsCTor->inside_radius, pdmsCTor->outside_radius, pdmsCTor->angle/**M_PI/180.0*/, false, 0, 0, pdmsCTor->name);
}
break;
case PDMS_RTORUS:
{
PdmsTools::PdmsObjects::RTorus* pdmsRTor = static_cast<PdmsTools::PdmsObjects::RTorus*>(currentPair.first);
primitive = new ccTorus(pdmsRTor->inside_radius, pdmsRTor->outside_radius, pdmsRTor->angle/**M_PI/180.0*/, false, pdmsRTor->height, 0, pdmsRTor->name);
}
break;
case PDMS_DISH:
{
PdmsTools::PdmsObjects::Dish* pdmsDish = static_cast<PdmsTools::PdmsObjects::Dish*>(currentPair.first);
primitive = new ccDish(pdmsDish->diameter / 2, pdmsDish->height, pdmsDish->radius, 0, pdmsDish->name);
}
break;
case PDMS_CONE:
{
PdmsTools::PdmsObjects::Cone* pdmsCone = static_cast<PdmsTools::PdmsObjects::Cone*>(currentPair.first);
primitive = new ccCone(pdmsCone->dbottom / 2, pdmsCone->dtop / 2, pdmsCone->height, 0, 0, 0, pdmsCone->name);
}
break;
case PDMS_PYRAMID:
unsupportedPrimitiveStr = "Pyramid";
break;
case PDMS_SNOUT:
{
PdmsTools::PdmsObjects::Snout* pdmsSnout = static_cast<PdmsTools::PdmsObjects::Snout*>(currentPair.first);
primitive = new ccCone(pdmsSnout->dbottom / 2, pdmsSnout->dtop / 2, pdmsSnout->height, pdmsSnout->xoff, pdmsSnout->yoff, 0, pdmsSnout->name);
}
break;
case PDMS_BOX:
{
PdmsTools::PdmsObjects::Box* pdmsBox = static_cast<PdmsTools::PdmsObjects::Box*>(currentPair.first);
primitive = new ccBox(pdmsBox->lengths, 0, pdmsBox->name);
}
break;
case PDMS_NBOX:
unsupportedPrimitiveStr = "NBox";
break;
case PDMS_EXTRU:
{
PdmsTools::PdmsObjects::Extrusion* pdmsExtru = static_cast<PdmsTools::PdmsObjects::Extrusion*>(currentPair.first);
size_t count = pdmsExtru->loop->loop.size();
if (count)
{
std::vector<CCVector2> profile;
profile.reserve(count);
for (std::list<PdmsTools::PdmsObjects::Vertex*>::const_iterator it = pdmsExtru->loop->loop.begin(); it != pdmsExtru->loop->loop.end(); ++it)
profile.push_back((*it)->v);
primitive = new ccExtru(profile, pdmsExtru->height, 0, pdmsExtru->name);
}
}
break;
case PDMS_NEXTRU:
unsupportedPrimitiveStr = "NExtru";
break;
case PDMS_LOOP:
unsupportedPrimitiveStr = "Loop";
break;
case PDMS_VERTEX:
unsupportedPrimitiveStr = "Vertex";
break;
default:
break;
}
if (primitive)
{
//transformation
ccGLMatrix trans;
assert(currentPair.first->isCoordinateSystemUpToDate);
trans.setTranslation(currentPair.first->position);
for (unsigned c = 0; c < 3; ++c)
for (unsigned l = 0; l < 3; ++l)
trans.getColumn(c)[l] = static_cast<float>(currentPair.first->orientation[c].u[l]);
primitive->setGLTransformation(trans);
primitive->setVisible(true);
currentPair.second->addChild(primitive);
}
else
{
ccLog::Warning(QString("[PDMSFilter] Primitive '%1' not supported yet!").arg(unsupportedPrimitiveStr));
}
}
}
}
else
{
return CC_FERR_MALFORMED_FILE;
}
container.applyGLTransformation_recursive();
return CC_FERR_NO_ERROR;
}
|