<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>Update: from the vtkKMeansStatistics reference page it sounds like it's necessary for the first column to be a vtkIdType array in order for learning to be used and the table available on the output port. I added this, but it does not solve my problem. However, I may have done so incorrectly. I am including my code below.</div><div><br></div><div>Thanks,</div><div>Sara</div><div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">        </span></span>//get data from the file</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>vtkXMLPolyDataReader* reader = vtkXMLPolyDataReader::New();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>reader->SetFileName( inputFile );</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>reader->Update();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>vtkPolyData* polydata = reader->GetOutput();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>cout << <span style="color: #c41a16">"Reading data"</span> << endl;</div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"><span class="Apple-tab-span" style="white-space:pre">        </span><br class="webkit-block-placeholder"></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>vtkSmartPointer<vtkFloatArray> magnitudeArray = vtkFloatArray::SafeDownCast(polydata->GetPointData()->GetArray(FeatureInArrayName));</div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"><span class="Apple-tab-span" style="white-space:pre">        </span><br class="webkit-block-placeholder"></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">        </span></span>// set up table for KMeans</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(196, 26, 22); "><span class="Apple-style-span" style="color: rgb(0, 0, 0); "><span class="Apple-tab-span" style="white-space:pre">        </span>vtkSmartPointer<vtkTable> inputData = vtkSmartPointer<vtkTable>::New();</span></div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"><span class="Apple-tab-span" style="white-space:pre">        </span><br class="webkit-block-placeholder"></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">        </span></span>// first column for kmeans clusters, vtkIdType</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>vtkSmartPointer<vtkIdTypeArray> idArray = vtkSmartPointer<vtkIdTypeArray>::New();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "> <span class="Apple-tab-span" style="white-space:pre">        </span>idArray->SetNumberOfComponents(<span style="color: #1c00cf">1</span>);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "> <span class="Apple-tab-span" style="white-space:pre">        </span>idArray->SetName( <span style="color: #c41a16">"KMeans"</span> );</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "> <span class="Apple-tab-span" style="white-space:pre">        </span>idArray->SetNumberOfTuples(polydata->GetNumberOfPoints());</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>inputData->AddColumn( idArray );</div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"><span class="Apple-tab-span" style="white-space:pre">        </span><br class="webkit-block-placeholder"></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">        </span></span>// second column for data values</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>vtkSmartPointer<vtkFloatArray> floatArray = vtkSmartPointer<vtkFloatArray>::New();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>floatArray->SetNumberOfComponents(<span style="color: #1c00cf">1</span>);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>floatArray->SetName( <span style="color: #c41a16">"ScalerMagnitude"</span> );</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>floatArray->SetNumberOfTuples(polydata->GetNumberOfPoints());</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>inputData->AddColumn( magnitudeArray );</div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"><span class="Apple-tab-span" style="white-space:pre">        </span><br class="webkit-block-placeholder"></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">        </span></span>// KMeans Set up</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(196, 26, 22); "><span class="Apple-style-span" style="color: rgb(0, 0, 0); "><span class="Apple-tab-span" style="white-space:pre">        </span>vtkSmartPointer<vtkKMeansStatistics> kMeansStatistics = vtkSmartPointer<vtkKMeansStatistics>::New();</span></div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"><span class="Apple-tab-span" style="white-space:pre">        </span><br class="webkit-block-placeholder"></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>kMeansStatistics->SetInput( vtkStatisticsAlgorithm::INPUT_DATA, inputData );</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>kMeansStatistics->SetColumnStatus( inputData->GetColumnName( <span style="color: #1c00cf">0</span> ) , <span style="color: #1c00cf">1</span> );</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>kMeansStatistics->SetColumnStatus( inputData->GetColumnName( <span style="color: #1c00cf">1</span> ) , <span style="color: #1c00cf">1</span> );</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>kMeansStatistics->RequestSelectedColumns();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>kMeansStatistics->SetDefaultNumberOfClusters( clusterCount );</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>kMeansStatistics->SetAssessOption( <span style="color: #1c00cf">1</span> );<span class="Apple-tab-span" style="white-space:pre">        </span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>kMeansStatistics->SetLearnOption( <span style="color: #1c00cf">1</span> ); </div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>kMeansStatistics->SetMaxNumIterations( <span style="color: #1c00cf">1</span> );</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>kMeansStatistics->Update() ;</div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"><span class="Apple-tab-span" style="white-space:pre">        </span><br class="webkit-block-placeholder"></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">        </span></span>//vtkTable* tab = vtkTable::SafeDownCast( kMeansStatistics->GetOutputDataObject( 1 ).GetBlock( 0 ) );</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; color: rgb(0, 116, 0); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">        </span></span>//double xc = tab->GetValueByName( label, "x" ).ToDouble();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>kMeansStatistics->GetOutputDataObject(<span style="color: #1c00cf">1</span>).GetBlock( <span style="color: #1c00cf">0</span> ); </div></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><br></div><div><br></div><div>On Mar 18, 2011, at 4:30 PM, Sara Rolfe wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">I agree. I also think that the example on the wiki might be more helpful if it showed this method of accessing the means. <div><br></div><div>However, I'm still having some trouble accessing the first block of the k-means output, when I use: </div><div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>vtkTable* tab = vtkTable::SafeDownCast( kMeansStatistics->GetOutputDataObject( <span style="color: #1c00cf">1</span> ).GetBlock( <span style="color: #1c00cf">0</span> ) );</div><div><br></div><div>or just </div><div><span class="Apple-style-span" style="font-family: Monaco; font-size: 10px; "><span class="Apple-tab-span" style="white-space:pre">        </span></span><span class="Apple-style-span" style="font-family: Monaco; font-size: 10px; ">kMeansStatistics->GetOutputDataObject(</span><span class="Apple-style-span" style="font-family: Monaco; font-size: 10px; "> </span><span class="Apple-style-span" style="font-family: Monaco; font-size: 10px; "><span style="color: rgb(28, 0, 207); ">1</span></span><span class="Apple-style-span" style="font-family: Monaco; font-size: 10px; "> </span><span class="Apple-style-span" style="font-family: Monaco; font-size: 10px; ">).GetBlock(</span><span class="Apple-style-span" style="font-family: Monaco; font-size: 10px; "> </span><span class="Apple-style-span" style="font-family: Monaco; font-size: 10px; "><span style="color: rgb(28, 0, 207); ">0</span></span><span class="Apple-style-span" style="font-family: Monaco; font-size: 10px; "> </span><span class="Apple-style-span" style="font-family: Monaco; font-size: 10px; ">)</span></div><div><span class="Apple-style-span" style="font-family: Monaco; font-size: 10px; "><br></span></div><div><span class="Apple-style-span" style="font-family: Monaco; font-size: 10px; "><div><div style="font-family: Helvetica; font-size: medium; ">I'm getting the following error: </div></div><div><br></div><div>error: request for member ‘GetBlock’ in ‘kMeansStatistics. vtkSmartPointer<T>::operator-> [with T = vtkKMeansStatistics]()->vtkKMeansStatistics::<anonymous>.vtkStatisticsAlgorithm::<anonymous>.vtkTableAlgorithm::<anonymous>.vtkAlgorithm::GetOutputDataObject(1)’, which is of non-class type ‘vtkDataObject*’</div><div><br></div><div><div style="font-family: Helvetica; font-size: medium; ">Does anyone know what might cause this?</div></div><div style="font-family: Helvetica; font-size: medium; "><br></div><div style="font-family: Helvetica; font-size: medium; ">Thanks,</div><div style="font-family: Helvetica; font-size: medium; ">Sara</div><div><br></div></span></div><div><div>On Mar 16, 2011, at 5:32 PM, David Doria wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>On Wed, Mar 16, 2011 at 4:07 PM, Sara Rolfe <<a href="mailto:smrolfe@u.washington.edu">smrolfe@u.washington.edu</a>> wrote:<br><blockquote type="cite"><br></blockquote><blockquote type="cite">Hi David,<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">It's not a difficult fix, I mainly found it awkward since I thought I was missing something simple. I understand how it works better now and can certainly implement it this way. I appreciate your clarification.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Sara<br></blockquote><br>If you recall, I had the same sort of "it feels awkward" issues a<br>while back. I think the problem is that the suite is very very capable<br>and able to hand very large and serious problems, but many users just<br>want the "very basic" functionality ("which points belong to which<br>cluster?", and "what are the cluster means?"), which is hard to get<br>at. There are many layers of complexity above that that a user must<br>understand (i.e. this "Learn" and "Derive" that you mentioned) that<br>are not concepts in a standard textbook explanation of kmeans<br>clustering. Providing a "simple" interface to do this "one pass" type<br>of thing would definitely be a nice addition.<br><br>That is, replace:<br><br> kMeansStatistics->SetLearnOption( 1 ); // This is on by default.<br> kMeansStatistics->SetMaxNumIterations( 1 );<br> vtkTable* tab = vtkTable::SafeDownCast(<br>kMeansStatistics->GetOutputDataObject( 1 ).GetBlock( 0 ) );<br> double xc = tab->GetValueByName( label, "x" ).ToDouble();<br><br>with<br><br>double mean0[3];<br>kMeans->GetMean(0,mean0);<br><br>See the difference :) ?<br><br>David D.<br></div></blockquote></div><br></div></div>_______________________________________________<br>Powered by <a href="http://www.kitware.com">www.kitware.com</a><br><br>Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html">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">http://www.vtk.org/Wiki/VTK_FAQ</a><br><br>Follow this link to subscribe/unsubscribe:<br><a href="http://www.vtk.org/mailman/listinfo/vtkusers">http://www.vtk.org/mailman/listinfo/vtkusers</a><br></blockquote></div><br></body></html>