<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-2022-jp">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p style="margin-top:0;margin-bottom:0">Hi,</p>
<p style="margin-top:0;margin-bottom:0">It doesn't work.</p>
<p style="margin-top:0;margin-bottom:0">I changed the lines, but the identifier "point" is undefined.</p>
------------------------------------------------<br>
And I have another question here,
<div>These codes could read polydata vtk, but failed to visualize.</div>
<div>I have another dataset (approximate 2000 set) that I saved by using Paraview into .vtk (the data is saved into unstructured grid data instead of polydata)</div>
<div><span style="font-size: 12pt;">Then, I tried to open using the following codes but i</span><span style="font-size: 12pt;">t failed to load for unstructured grid </span><span style="font-size: 12pt;">data.</span></div>
<div>
<div style="color: rgb(0, 0, 0);">How should i modify the lines to read the unstructured grid dataset?</div>
<div style="color: rgb(0, 0, 0);"><br>
</div>
<div style="color: rgb(0, 0, 0);">Thank you so much.</div>
<div style="color: rgb(0, 0, 0);"><br>
</div>
<div style="color: rgb(0, 0, 0);">Polly<br>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> kenichiro yoshimi <rccm.kyoshimi@gmail.com><br>
<b>Sent:</b> Thursday, August 30, 2018 9:16 AM<br>
<b>To:</b> polly_sukting@hotmail.com<br>
<b>Cc:</b> vtkusers<br>
<b>Subject:</b> Re: [vtkusers] How to visualize polydata after KmeansClustering?</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Hi,<br>
<br>
Could you try to modify the lines of your code as below?<br>
<br>
  vtkSmartPointer<vtkPolyData> polydata =<br>
    vtkSmartPointer<vtkPolyData>::New();<br>
==><br>
  vtkSmartPointer<vtkPolyData> polydata = point;<br>
<br>
Regards<br>
2018$BG/(B8$B7n(B26$BF|(B($BF|(B) 1:59 Polly Pui <polly_sukting@hotmail.com>:<br>
><br>
> Hi,<br>
><br>
> I would like to show my polydata with points and mark with colours after the KmeansClustering process.<br>
><br>
> However, I could only get the values of the points without the visualization of the data.<br>
><br>
> Can anyone please advice?<br>
><br>
> Thank you so much.<br>
><br>
><br>
> Polly<br>
><br>
> --------------------------------------------------------------------------------------<br>
><br>
> My code is as below:<br>
><br>
> int main(int argc, char* argv[])<br>
> {<br>
> // Get the points into the format needed for KMeans<br>
> vtkSmartPointer<vtkPolyData> point =<br>
> vtkSmartPointer<vtkPolyData>::New();<br>
><br>
> vtkSmartPointer<vtkPolyDataReader> reader =<br>
> vtkSmartPointer<vtkPolyDataReader>::New();<br>
> reader->SetFileName(argv[1]);<br>
> reader->Update();<br>
><br>
> point = reader->GetOutput();<br>
><br>
> vtkSmartPointer<vtkTable> inputData =<br>
> vtkSmartPointer<vtkTable>::New();<br>
><br>
> for (int c = 0; c < 3; ++c)<br>
> {<br>
> std::stringstream colName;<br>
> colName << "coord " << c;<br>
> vtkSmartPointer<vtkDoubleArray> doubleArray =<br>
> vtkSmartPointer<vtkDoubleArray>::New();<br>
> doubleArray->SetNumberOfComponents(1);<br>
> doubleArray->SetName(colName.str().c_str());<br>
> doubleArray->SetNumberOfTuples(point->GetNumberOfPoints());<br>
><br>
> for (int r = 0; r < point->GetNumberOfPoints(); ++r)<br>
> {<br>
> double p[3];<br>
> point->GetPoint(r, p);<br>
> doubleArray->SetValue(r, p[c]);<br>
> }<br>
> inputData->AddColumn(doubleArray);<br>
> }<br>
><br>
> vtkSmartPointer<vtkKMeansStatistics> kMeansStatistics =<br>
> vtkSmartPointer<vtkKMeansStatistics>::New();<br>
><br>
> #if VTK_MAJOR_VERSION <= 5<br>
> kMeansStatistics->SetInput(vtkStatisticsAlgorithm::INPUT_DATA, inputData);<br>
> #else<br>
> kMeansStatistics->SetInputData(vtkStatisticsAlgorithm::INPUT_DATA, inputData);<br>
> #endif<br>
> kMeansStatistics->SetColumnStatus(inputData->GetColumnName(0), 1);<br>
> kMeansStatistics->SetColumnStatus(inputData->GetColumnName(1), 1);<br>
> kMeansStatistics->SetColumnStatus(inputData->GetColumnName(2), 1);<br>
> kMeansStatistics->RequestSelectedColumns();<br>
> kMeansStatistics->SetAssessOption(true);<br>
> kMeansStatistics->SetDefaultNumberOfClusters(5);<br>
> //kMeansStatistics->SetMaxNumIterations(1);<br>
> kMeansStatistics->Update();<br>
> //double mean0[3];<br>
> //kMeansStatistics->GetMean(0, mean0);<br>
> // Display the results<br>
> kMeansStatistics->GetOutput()->Dump();<br>
> //Group the points according to ID number<br>
> vtkSmartPointer<vtkIntArray> clusterArray =<br>
> vtkSmartPointer<vtkIntArray>::New();<br>
> clusterArray->SetNumberOfComponents(1);<br>
> clusterArray->SetName("ClusterId");<br>
><br>
> for (int r = 0; r < kMeansStatistics->GetOutput()->GetNumberOfRows(); r++)<br>
> {<br>
> vtkVariant v = kMeansStatistics->GetOutput()->GetValue(r, kMeansStatistics->GetOutput()->GetNumberOfColumns() - 1);<br>
> //std::cout << "Point " << r << " is in cluster " << v.ToInt() << std::endl;<br>
> clusterArray->InsertNextValue(v.ToInt());<br>
> }<br>
><br>
> // Create a lookup table to map cell data to colors<br>
> vtkSmartPointer<vtkLookupTable> lut =<br>
> vtkSmartPointer<vtkLookupTable>::New();<br>
> int tableSize = (kMeansStatistics + 1, 10);<br>
> lut->SetNumberOfTableValues(tableSize);<br>
> lut->Build();<br>
><br>
> // Fill in a few known colors, the rest will be generated if needed<br>
> //ColorCells tutorial <a href="https://lorensen.github.io/VTKExamples/site/Cxx/PolyData/ColorCells/" id="LPlnk558441" class="OWAAutoLink" previewremoved="true">
https://lorensen.github.io/VTKExamples/site/Cxx/PolyData/ColorCells/</a>
<div id="LPBorder_GT_15356023997230.5337224108616749" style="margin-bottom: 20px; overflow: auto; width: 100%; text-indent: 0px;">
<table id="LPContainer_15356023997210.34313217316301725" role="presentation" cellspacing="0" style="width: 90%; background-color: rgb(255, 255, 255); position: relative; overflow: auto; padding-top: 20px; padding-bottom: 20px; margin-top: 20px; border-top: 1px dotted rgb(200, 200, 200); border-bottom: 1px dotted rgb(200, 200, 200);">
<tbody>
<tr valign="top" style="border-spacing: 0px;">
<td id="TextCell_15356023997220.30137470511062037" colspan="2" style="vertical-align: top; position: relative; padding: 0px; display: table-cell;">
<div id="LPRemovePreviewContainer_15356023997220.13396815820813224"></div>
<div id="LPTitle_15356023997220.4018160620827407" style="top: 0px; color: rgb(220, 79, 173); font-weight: 400; font-size: 21px; font-family: wf_segoe-ui_light, "Segoe UI Light", "Segoe WP Light", "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif; line-height: 21px;">
<a id="LPUrlAnchor_15356023997220.5948740729354214" href="https://lorensen.github.io/VTKExamples/site/Cxx/PolyData/ColorCells/" target="_blank" style="text-decoration: none;">ColorCells - GitHub Pages</a></div>
<div id="LPMetadata_15356023997220.8426104356616066" style="margin: 10px 0px 16px; color: rgb(102, 102, 102); font-weight: 400; font-family: wf_segoe-ui_normal, "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif; font-size: 14px; line-height: 14px;">
lorensen.github.io</div>
<div id="LPDescription_15356023997230.5433740208866051" style="display: block; color: rgb(102, 102, 102); font-weight: 400; font-family: wf_segoe-ui_normal, "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif; font-size: 14px; line-height: 20px; max-height: 100px; overflow: hidden;">
Download and Build ColorCells$B"y(B. Click here to download ColorCells and its CMakeLists.txt file. Once the tarball ColorCells.tar has been downloaded and extracted,</div>
</td>
</tr>
</tbody>
</table>
</div>
<br>
<br>
> vtkSmartPointer<vtkNamedColors> colors =<br>
> vtkSmartPointer<vtkNamedColors>::New();<br>
> lut->SetTableValue(0, colors->GetColor4d("Black").GetData());<br>
> lut->SetTableValue(1, colors->GetColor4d("Banana").GetData());<br>
> lut->SetTableValue(2, colors->GetColor4d("Tomato").GetData());<br>
> lut->SetTableValue(3, colors->GetColor4d("Peacock").GetData());<br>
> lut->SetTableValue(4, colors->GetColor4d("Lavender").GetData());<br>
><br>
> // Output the cluster centers<br>
><br>
> vtkMultiBlockDataSet* outputMetaDS = vtkMultiBlockDataSet::SafeDownCast(kMeansStatistics->GetOutputDataObject(vtkStatisticsAlgorithm::OUTPUT_MODEL));<br>
> vtkSmartPointer<vtkTable> outputMeta = vtkTable::SafeDownCast(outputMetaDS->GetBlock(0));<br>
> //vtkSmartPointer<vtkTable> outputMeta = vtkTable::SafeDownCast( outputMetaDS->GetBlock( 1 ) );<br>
> vtkDoubleArray* coord0 = vtkDoubleArray::SafeDownCast(outputMeta->GetColumnByName("coord 0"));<br>
> vtkDoubleArray* coord1 = vtkDoubleArray::SafeDownCast(outputMeta->GetColumnByName("coord 1"));<br>
> vtkDoubleArray* coord2 = vtkDoubleArray::SafeDownCast(outputMeta->GetColumnByName("coord 2"));<br>
><br>
> for (unsigned int i = 0; i < coord0->GetNumberOfTuples(); ++i)<br>
> {<br>
> std::cout << coord0->GetValue(i) << " " << coord1->GetValue(i) << " " << coord2->GetValue(i) << std::endl;<br>
> }<br>
><br>
> vtkSmartPointer<vtkPolyData> polydata =<br>
> vtkSmartPointer<vtkPolyData>::New();<br>
> //polydata->SetPoints(point);<br>
> polydata->GetPointData()->AddArray(clusterArray);<br>
> polydata->GetPointData()->SetScalars(clusterArray);<br>
><br>
> // Display<br>
> vtkSmartPointer<vtkVertexGlyphFilter> glyphFilter =<br>
> vtkSmartPointer<vtkVertexGlyphFilter>::New();<br>
> #if VTK_MAJOR_VERSION <= 5<br>
> glyphFilter->SetInputConnection(polydata->GetProducerPort());<br>
> #else<br>
> glyphFilter->SetInputData(polydata);<br>
> #endif<br>
> glyphFilter->Update();<br>
><br>
> // Create a mapper and actor<br>
> vtkSmartPointer<vtkPolyDataMapper> mapper =<br>
> vtkSmartPointer<vtkPolyDataMapper>::New();<br>
> mapper->SetInputConnection(glyphFilter->GetOutputPort());<br>
> mapper->SetScalarRange(0, tableSize - 1);<br>
> mapper->SetLookupTable(lut);<br>
><br>
> vtkSmartPointer<vtkActor> actor =<br>
> vtkSmartPointer<vtkActor>::New();<br>
> actor->SetMapper(mapper);<br>
> actor->GetProperty()->SetPointSize(5);<br>
><br>
> // Create a renderer, render window, and interactor<br>
> vtkSmartPointer<vtkRenderer> renderer =<br>
> vtkSmartPointer<vtkRenderer>::New();<br>
> vtkSmartPointer<vtkRenderWindow> renderWindow =<br>
> vtkSmartPointer<vtkRenderWindow>::New();<br>
> renderWindow->AddRenderer(renderer);<br>
> renderWindow->SetSize(800, 800);<br>
><br>
> vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =<br>
> vtkSmartPointer<vtkRenderWindowInteractor>::New();<br>
> renderWindowInteractor->SetRenderWindow(renderWindow);<br>
><br>
> // Add the actor to the scene<br>
> renderer->AddActor(actor);<br>
> renderer->SetBackground(colors->GetColor3d("SlateGray").GetData());<br>
><br>
> vtkSmartPointer<vtkInteractorStyleTrackballCamera> style =<br>
> vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();<br>
> renderWindowInteractor->SetInteractorStyle(style);<br>
><br>
> // Render and interact<br>
> renderWindow->Render();<br>
><br>
> vtkWindowToImageFilter *windowToImageFilter = vtkWindowToImageFilter::New();<br>
> windowToImageFilter->SetInput(renderWindow);<br>
> windowToImageFilter->Update();<br>
><br>
> vtkJPEGWriter *writer = vtkJPEGWriter::New();<br>
> writer->SetInputConnection(windowToImageFilter->GetOutputPort());<br>
> writer->SetFileName("10nosepoints.jpg");<br>
> writer->Write();<br>
><br>
> renderWindowInteractor->Start();<br>
><br>
> return EXIT_SUCCESS;<br>
> }<br>
><br>
> _______________________________________________<br>
> Powered by <a href="http://www.kitware.com" id="LPlnk970864" class="OWAAutoLink" previewremoved="true">
www.kitware.com</a><br>
><br>
> Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" id="LPlnk395681" class="OWAAutoLink" previewremoved="true">
http://www.kitware.com/opensource/opensource.html</a><br>
><br>
> Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" id="LPlnk784491" class="OWAAutoLink" previewremoved="true">
http://www.vtk.org/Wiki/VTK_FAQ</a><br>
><br>
> Search the list archives at: <a href="http://markmail.org/search/?q=vtkusers" id="LPlnk212231" class="OWAAutoLink" previewremoved="true">
http://markmail.org/search/?q=vtkusers</a><br>
><br>
> Follow this link to subscribe/unsubscribe:<br>
> <a href="https://public.kitware.com/mailman/listinfo/vtkusers" id="LPlnk293147" class="OWAAutoLink" previewremoved="true">
https://public.kitware.com/mailman/listinfo/vtkusers</a><br>
</div>
</span></font></div>
</div>
</div>
</div>
</body>
</html>