<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Hi,</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Thanks for your reply.</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Is it possible to have more elaborations from you?</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
How can I get the number of points from vtkTableToPolyData?</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
I got an error saying that vtkTableToPolyData has no members of GetNumberOfPoints.</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
I need those points to proceed to KmeansStatistics.</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
This is my code:</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
......</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<span>std::string inputFilename = argv[1];<br>
</span>
<div><br>
</div>
<div>vtkSmartPointer<vtkDelimitedTextReader> reader =<br>
</div>
<div> vtkSmartPointer<vtkDelimitedTextReader>::New();<br>
</div>
<div>reader->SetFileName(inputFilename.c_str());<br>
</div>
<div>reader->SetFieldDelimiterCharacters(" ");<br>
</div>
<div>reader->DetectNumericColumnsOn();<br>
</div>
<div>reader->Update();<br>
</div>
<div>int numberOfRows = reader->GetOutput()->GetNumberOfRows();<br>
</div>
<div><br>
</div>
<div>vtkSmartPointer<vtkTableToPolyData> inputData =<br>
</div>
<div> vtkSmartPointer<vtkTableToPolyData>::New();<br>
</div>
<div>inputData->SetInputConnection(reader->GetOutputPort);<br>
</div>
<div><br>
</div>
<div>for (int c = 0; c < 3; ++c)<br>
</div>
<div>{<br>
</div>
<div> std::stringstream colName;<br>
</div>
<div> colName << "coord " << c;<br>
</div>
<div> vtkSmartPointer<vtkDoubleArray> doubleArray =<br>
</div>
<div> vtkSmartPointer<vtkDoubleArray>::New();<br>
</div>
<div> doubleArray->SetNumberOfComponents(1);<br>
</div>
<div> doubleArray->SetName(colName.str().c_str());<br>
</div>
<div> doubleArray->SetNumberOfTuples(inputData->GetNumberOfPoints());<br>
</div>
<div><br>
</div>
<div><br>
</div>
<div> for (int r = 0; r < inputData->GetNumberOfPoints(); ++r)<br>
</div>
<div> {<br>
</div>
<div> double p[3];<br>
</div>
<div> inputData->GetPoint(r, p);<br>
</div>
<div> doubleArray->SetValue(r, p[c]);<br>
</div>
<div> }<br>
</div>
<div> inputData->AddColumn(doubleArray);<br>
</div>
<div>}<br>
</div>
<div><br>
</div>
<div>vtkSmartPointer<vtkKMeansStatistics> kMeansStatistics =<br>
</div>
<div> vtkSmartPointer<vtkKMeansStatistics>::New();<br>
</div>
<div><br>
</div>
<div>#if VTK_MAJOR_VERSION <= 5<br>
</div>
<div>kMeansStatistics->SetInput(vtkStatisticsAlgorithm::INPUT_DATA, inputData);<br>
</div>
<div>#else<br>
</div>
<div>kMeansStatistics->SetInputData(vtkStatisticsAlgorithm::INPUT_DATA, inputData);<br>
</div>
<div>#endif<br>
</div>
<div>kMeansStatistics->SetColumnStatus(inputData->GetColumnName(0), 1);<br>
</div>
<div>kMeansStatistics->SetColumnStatus(inputData->GetColumnName(1), 1);<br>
</div>
<div>kMeansStatistics->SetColumnStatus(inputData->GetColumnName(2), 1);<br>
</div>
<div>kMeansStatistics->RequestSelectedColumns();<br>
</div>
<div>kMeansStatistics->SetAssessOption(true);<br>
</div>
<div>kMeansStatistics->SetDefaultNumberOfClusters(1);<br>
</div>
<div>//kMeansStatistics->SetMaxNumIterations(15);<br>
</div>
<span>kMeansStatistics->Update();</span><br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<span><br>
</span></div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<span>Thanks again.</span></div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<span><br>
</span></div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<span>Regards,</span></div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<span>Polly</span></div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> Cory Quammen <cory.quammen@kitware.com><br>
<b>Sent:</b> Friday, November 9, 2018 10:07 PM<br>
<b>To:</b> Polly Pui<br>
<b>Cc:</b> vtkusers<br>
<b>Subject:</b> Re: [vtkusers] Extract csv row and column into points</font>
<div> </div>
</div>
<div>
<div dir="ltr">vtkDelimitedTextReader -> vtkTableToPolyData is a pipeline that should make this much simpler.</div>
<br>
<div class="x_gmail_quote">
<div dir="ltr">On Fri, Nov 9, 2018 at 1:14 AM Polly Pui <<a href="mailto:polly_sukting@hotmail.com">polly_sukting@hotmail.com</a>> wrote:<br>
</div>
<blockquote class="x_gmail_quote" style="margin:0 0 0 .8ex; border-left:1px #ccc solid; padding-left:1ex">
<div dir="ltr">
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Hi,</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Is there any clue that i can extract the row and column data from a csv file and read them as points?</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Currently I am using <span style="font-size:16px; background-color:rgb(255,255,255); display:inline!important">
vtkpoints to </span>read points by inserting points manually to my .cpp .</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Is it possible for me to call the csv directly and read the data (eg. column 3-5, row 2-10)?</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
I attach my code here.</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
......</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<span>int main(int, char*[])<br>
</span>
<div>{<br>
</div>
<div><br>
</div>
<div>vtkSmartPointer<vtkPoints> points =<br>
</div>
<div> vtkSmartPointer<vtkPoints>::New();<br>
</div>
<div>points->InsertNextPoint(8.4312, -36.489, -1500.7);<br>
</div>
<div>points->InsertNextPoint(8.8408, -37.726, -1500.4);<br>
</div>
<div>points->InsertNextPoint(11.372, -37.787, -1501.5);<br>
</div>
<div>points->InsertNextPoint(11.263, -36.384, -1501.9);<br>
</div>
<div>points->InsertNextPoint(9.3914, -40.819, -1500.8);<br>
</div>
<div>points->InsertNextPoint(11.685, -42.482, -1502.7);<br>
</div>
<div>points->InsertNextPoint(14.235, -38.096, -1503.5);<br>
</div>
<div>points->InsertNextPoint(13.972, -43.051, -1504.2);<br>
</div>
<span>points->InsertNextPoint(9.22, -43.904, -1504);</span><br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<span><br>
</span></div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<span><span>vtkSmartPointer<vtkTable> inputData =<br>
</span><span> vtkSmartPointer<vtkTable>::New();</span><br>
</span></div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<span><span><span>for (int c = 0; c < 3; ++c)<br>
</span>
<div>{<br>
</div>
<div> std::stringstream colName;<br>
</div>
<div> colName << "coord " << c;<br>
</div>
<div> vtkSmartPointer<vtkDoubleArray> doubleArray =<br>
</div>
<div> vtkSmartPointer<vtkDoubleArray>::New();<br>
</div>
<div> doubleArray->SetNumberOfComponents(1);<br>
</div>
<div> doubleArray->SetName(colName.str().c_str());<br>
</div>
<div> doubleArray->SetNumberOfTuples(points->GetNumberOfPoints());<br>
</div>
<div><br>
</div>
<div> for (int r = 0; r < points->GetNumberOfPoints(); ++r)<br>
</div>
<div> {<br>
</div>
<div> double p[3];<br>
</div>
<div> points->GetPoint(r, p);<br>
</div>
<div> doubleArray->SetValue(r, p[c]);<br>
</div>
<div> }<br>
</div>
<div> inputData->AddColumn(doubleArray);<br>
</div>
<span>}</span><br>
</span></span></div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Thank you very much.</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Regards,</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Polly</div>
</div>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" rel="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" 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" 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" 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" target="_blank">https://public.kitware.com/mailman/listinfo/vtkusers</a><br>
</blockquote>
</div>
<br clear="all">
<div><br>
</div>
-- <br>
<div dir="ltr" class="x_gmail_signature">Cory Quammen<br>
Staff R&D Engineer<br>
Kitware, Inc.</div>
</div>
</body>
</html>