<div dir="auto">Send me the working codr and I'll ad it as a VTKExample. You'll get credit of course.</div><br><div class="gmail_quote"><div dir="ltr">On Thu, Aug 30, 2018, 9:06 AM Polly Pui <<a href="mailto:polly_sukting@hotmail.com">polly_sukting@hotmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">




<div dir="ltr">
<div id="m_5779788548813304232divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif" dir="ltr">
<p style="margin-top:0;margin-bottom:0"><br>
</p>
Hi,
<div>The code works well now. I could visualize it.</div>
<div>I made a mistake by changing into a different line. </div>
<div>Thank you so much.</div>
<div><br>
Polly<br>
<div style="color:rgb(0,0,0)">
<hr style="display:inline-block;width:98%">
<div id="m_5779788548813304232divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> vtkusers <<a href="mailto:vtkusers-bounces@public.kitware.com" target="_blank" rel="noreferrer">vtkusers-bounces@public.kitware.com</a>> on behalf of Polly Pui <<a href="mailto:polly_sukting@hotmail.com" target="_blank" rel="noreferrer">polly_sukting@hotmail.com</a>><br>
<b>Sent:</b> Thursday, August 30, 2018 12:22 PM<br>
<b>To:</b> kenichiro yoshimi<br>
<b>Cc:</b> vtkusers<br>
<b>Subject:</b> Re: [vtkusers] How to visualize polydata after KmeansClustering?</font>
<div> </div>
</div>

<div dir="ltr">
<div id="m_5779788548813304232x_divtagdefaultwrapper" dir="ltr" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif">
<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%">
<div id="m_5779788548813304232x_divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> kenichiro yoshimi <<a href="mailto:rccm.kyoshimi@gmail.com" target="_blank" rel="noreferrer">rccm.kyoshimi@gmail.com</a>><br>
<b>Sent:</b> Thursday, August 30, 2018 9:16 AM<br>
<b>To:</b> <a href="mailto:polly_sukting@hotmail.com" target="_blank" rel="noreferrer">polly_sukting@hotmail.com</a><br>
<b>Cc:</b> vtkusers<br>
<b>Subject:</b> Re: [vtkusers] How to visualize polydata after KmeansClustering?</font>
<div> </div>
</div>
<div class="m_5779788548813304232x_BodyFragment"><font size="2"><span style="font-size:11pt">
<div class="m_5779788548813304232x_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年8月26日(日) 1:59 Polly Pui <<a href="mailto:polly_sukting@hotmail.com" target="_blank" rel="noreferrer">polly_sukting@hotmail.com</a>>:<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="m_5779788548813304232LPlnk558441" class="m_5779788548813304232x_OWAAutoLink" target="_blank" rel="noreferrer">
https://lorensen.github.io/VTKExamples/site/Cxx/PolyData/ColorCells/</a>
<div id="m_5779788548813304232LPBorder_GT_15356023997230.5337224108616749" style="margin-bottom:20px;overflow:auto;width:100%;text-indent:0px">
<table id="m_5779788548813304232LPContainer_15356023997210.34313217316301725" cellspacing="0" style="width:90%;background-color:rgb(255,255,255);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="m_5779788548813304232x_TextCell_15356023997220.30137470511062037" colspan="2" style="vertical-align:top;padding:0px;display:table-cell">
<div id="m_5779788548813304232LPRemovePreviewContainer_15356023997220.13396815820813224"></div>
<div id="m_5779788548813304232LPTitle_15356023997220.4018160620827407" style="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="m_5779788548813304232LPUrlAnchor_15356023997220.5948740729354214" href="https://lorensen.github.io/VTKExamples/site/Cxx/PolyData/ColorCells/" style="text-decoration:none" target="_blank" rel="noreferrer">ColorCells - GitHub Pages</a></div>
<div id="m_5779788548813304232LPMetadata_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">
<a href="http://lorensen.github.io" target="_blank" rel="noreferrer">lorensen.github.io</a></div>
<div id="m_5779788548813304232LPDescription_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¶. 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="m_5779788548813304232LPlnk970864" class="m_5779788548813304232x_OWAAutoLink" target="_blank" rel="noreferrer">
www.kitware.com</a><br>
><br>
> Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" id="m_5779788548813304232LPlnk395681" class="m_5779788548813304232x_OWAAutoLink" target="_blank" rel="noreferrer">
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="m_5779788548813304232LPlnk784491" class="m_5779788548813304232x_OWAAutoLink" target="_blank" rel="noreferrer">
http://www.vtk.org/Wiki/VTK_FAQ</a><br>
><br>
> Search the list archives at: <a href="http://markmail.org/search/?q=vtkusers" id="m_5779788548813304232LPlnk212231" class="m_5779788548813304232x_OWAAutoLink" target="_blank" rel="noreferrer">
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="m_5779788548813304232LPlnk293147" class="m_5779788548813304232x_OWAAutoLink" target="_blank" rel="noreferrer">
https://public.kitware.com/mailman/listinfo/vtkusers</a><br>
</div>
</span></font></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

_______________________________________________<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer noreferrer" target="_blank">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" rel="noreferrer noreferrer" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Search the list archives at: <a href="http://markmail.org/search/?q=vtkusers" rel="noreferrer noreferrer" target="_blank">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" rel="noreferrer noreferrer" target="_blank">https://public.kitware.com/mailman/listinfo/vtkusers</a><br>
</blockquote></div>