14 #include <vtkCellArray.h>
15 #include <vtkColorSeries.h>
16 #include <vtkPolyData.h>
17 #include <vtkPointData.h>
18 #include <QDomDocument>
21 #include <vtkTransformTextureCoords.h>
22 #include <vtkTexture.h>
23 #include <vtkTextureMapToCylinder.h>
24 #include <vtkTextureMapToPlane.h>
25 #include <vtkTextureMapToSphere.h>
29 #include "vtkProperty.h"
30 #include "vtkImageData.h"
50 Data(uid, name), mVtkPolyData(polyData), mHasGlyph(false), mOrientationArray(
""), mColorArray(
""), mPatientModelService(patientModelService),
51 mSpaceProvider(spaceProvider), mTextureData(patientModelService)
54 mVtkPolyData = vtkPolyDataPtr::New();
57 mShowGlyph = shouldGlyphBeEnableByDefault();
76 return mProperties.
mRepresentation->getValue().toInt() == VTK_WIREFRAME;
82 raw = filemanager->loadVtkPolyData(path);
86 this->
setName(QFileInfo(path).baseName());
94 mVtkPolyData = polyData;
95 mVtkPolyDataOriginal = mVtkPolyData;
96 mOrientationArrayList.clear();
97 mColorArrayList.clear();
102 for(
int k=0; k < mVtkPolyData->GetPointData()->GetNumberOfArrays(); k++)
104 num=mVtkPolyData->GetPointData()->GetArray(k)->GetNumberOfComponents();
107 if(strlen(mOrientationArray.c_str())==0)
109 mOrientationArray=mVtkPolyData->GetPointData()->GetArrayName(k);
112 mOrientationArrayList << mVtkPolyData->GetPointData()->GetArrayName(k);
115 mColorArrayList <<
"";
117 for(
int k=0; k < mVtkPolyData->GetPointData()->GetNumberOfArrays(); k++)
119 num=mVtkPolyData->GetPointData()->GetArray(k)->GetNumberOfComponents();
122 mColorArrayList << mVtkPolyData->GetPointData()->GetArrayName(k);
126 mShowGlyph = shouldGlyphBeEnableByDefault();
143 QDomDocument doc = dataNode.ownerDocument();
145 QDomNode meshNode = dataNode;
147 mProperties.
addXml(dataNode);
148 mTextureData.
addXml(dataNode);
150 QDomElement glyphNode = doc.createElement(
"glyph");
151 QDomElement elemGlyph = glyphNode.toElement();
152 elemGlyph.setAttribute(
"showGlyph", mShowGlyph);
153 elemGlyph.setAttribute(
"orientationArray", mOrientationArray.c_str());
154 elemGlyph.setAttribute(
"colorArray", mColorArray.c_str());
155 elemGlyph.setAttribute(
"glyphLUT", mGlyphLUT.c_str());
156 meshNode.appendChild(elemGlyph);
167 if (dataNode.isNull())
173 QDomNode glyphNode = dataNode.namedItem(
"glyph");
174 if (!glyphNode.isNull())
176 mShowGlyph = glyphNode.toElement().attribute(
"showGlyph").toInt();
177 mOrientationArray = glyphNode.toElement().attribute(
"orientationArray").toStdString();
178 mColorArray = glyphNode.toElement().attribute(
"colorArray").toStdString();
179 mGlyphLUT = glyphNode.toElement().attribute(
"glyphLUT").toStdString();
187 mProperties.
mColor->setValue(color);
192 return mProperties.
mColor->getValue();
242 bool Mesh::shouldGlyphBeEnableByDefault()
244 if(! mHasGlyph)
return false;
245 if(!mVtkPolyData)
return false;
246 if(mVtkPolyData->GetNumberOfVerts() > 0)
return false;
247 if(mVtkPolyData->GetNumberOfLines() > 0)
return false;
248 if(mVtkPolyData->GetNumberOfPolys() > 0)
return false;
249 if(mVtkPolyData->GetNumberOfStrips() > 0)
return false;
257 return mOrientationArray.c_str();
262 mOrientationArray = orientationArray;
268 return mProperties.
mVisSize->getValue();
273 mProperties.
mVisSize->setValue(size);
278 return mColorArray.c_str();
283 mColorArray = colorArray;
289 return mGlyphLUT.c_str();
299 mGlyphLUT = glyphLUT;
316 if(mVtkPolyDataOriginal)
317 mVtkPolyData = mVtkPolyDataOriginal;
323 if(!this->createTextureMapper(tMapper))
331 mVtkTexture = vtkTexturePtr::New();
332 mVtkTexture->SetRepeat(mTextureData.
getRepeat()->getValue());
333 mVtkTexture->SetInputData(vtkImageData);
339 transformTexture->SetInputConnection(tMapper->GetOutputPort());
342 transformTexture->SetPosition(-posR, -posS, 0);
345 transformTexture->SetScale(scaleR, scaleS, 1);
346 transformTexture->Update();
349 mVtkPolyData = transformTexture->GetPolyDataOutput();
358 tMapper = vtkTextureMapToCylinderPtr::New();
359 dynamic_cast<vtkTextureMapToCylinder*
>(tMapper.Get())->PreventSeamOn();
367 mapper->SetOrigin(bb.corner(0,0,1).data());
368 mapper->SetPoint1(bb.corner(1,0,1).data());
369 mapper->SetPoint2(bb.corner(0,1,1).data());
375 tMapper = vtkTextureMapToSpherePtr::New();
382 tMapper->SetInputData(mVtkPolyData);
388 return mOrientationArrayList;
393 return mColorArrayList;
428 floatPoints->DeepCopy(points);
429 floatPoints->SetDataTypeToFloat();
430 for (
int i = 0; i < poly->GetNumberOfPoints(); ++i)
434 floatPoints->SetPoint(i, p.begin());
436 poly->SetPoints(floatPoints.GetPointer());
445 return poly->GetLines()->GetNumberOfCells() > 0 && poly->GetPolys()->GetNumberOfCells() == 0 && poly->GetStrips()->GetNumberOfCells() == 0;
450 QString filename = basePath +
"/Images/" + this->
getUid() +
".vtk";
451 this->
setFilename(QDir(basePath).relativeFilePath(filename));
453 fileManager->save(
self, filename);