<div dir="ltr">My code is splitted in many parts... I hope this time it contains most related parts. It should be compilable if you put it into a main() function<div><br></div><div><div>const char *fileName_str = "xxxxx.obj";</div><div>vtkSmartPointer< vtkOBJReader > m_SkullMesh = vtkSmartPointer< vtkOBJReader >::New();</div><div>m_SkullMesh->SetFileName(fileName_str);</div><div>m_SkullMesh->Update();</div></div><div><br></div><div>double *skullTemplate = new double[3*meshNum];<br></div><div><div>int meshNum = m_SkullMesh->GetOutput()->GetNumberOfPoints();</div><div>for (int i = 0; i < meshNum; ++i) {</div><div><span class="" style="white-space:pre">         </span><font color="#ff0000">double* temp = m_SkullMesh->GetOutput()->GetPoint(i);</font></div><div><span class="" style="white-space:pre">             </span>skullTemplate[3*i] = temp[0];</div><div><span class="" style="white-space:pre">              </span>skullTemplate[3*i+1] = temp[1];</div><div><span class="" style="white-space:pre">            </span>skullTemplate[3*i+2] = temp[2];</div><div>}</div></div><div><br></div><div>I have called update before and I can indeed get access to each point using m_SkullMesh->GetOutput()->GetPoint(i). The code I post above is workable. After the for loop, all the points in vtkpolydata is stored in skullTemplate and have correct results. What I asked is that I think copy each point data into a double array is not a very efficient way and it should be possible to get the pointer to the internal array of all points. So I tried to use another way as below</div><div><br></div><div><div><div>const char *fileName_str = ba.data();</div><div>m_SkullMesh = vtkSmartPointer< vtkOBJReader >::New();</div><div>m_SkullMesh->SetFileName(fileName_str);</div><div>m_SkullMesh->Update();</div></div><div><br></div><div><div><font color="#ff0000">double *skullTemplate = vtkDoubleArray::SafeDownCast(m_SkullMesh->GetOutput()->GetPoints()->GetData())->GetPointer(0);</font><br></div></div></div><div><font color="#ff0000"><br></font></div><div><font color="#000000">This will have a run-time error.</font></div><div><font color="#000000"><br></font></div><div><font color="#000000">Best,</font></div><div><font color="#000000">Lin</font></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 17, 2014 at 7:56 PM, David Doria <span dir="ltr"><<a href="mailto:daviddoria@gmail.com" target="_blank">daviddoria@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><span class="">On Wed, Sep 17, 2014 at 7:52 AM, Lin M <span dir="ltr"><<a href="mailto:majcjc@gmail.com" target="_blank">majcjc@gmail.com</a>></span> wrote:<br></span><div class="gmail_extra"><div class="gmail_quote"><span class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Thank you for your advice, David.<div><br></div><div>I made a mistake, m_SkullMesh is a vtkOBJReader and the m_SkullMesh->GetOutput() should be a vtkPolyData.</div><div><br></div><div>I hope to get the point array of it. The code I wrote before could work properly</div><div><br></div><div><div><span style="white-space:pre-wrap">      </span>int meshNum = m_SkullMesh->GetOutput()->GetNumberOfPoints();</div><div><span style="white-space:pre-wrap">       </span>double *skullTemplate = new double[3*meshNum];</div><div><span style="white-space:pre-wrap">   </span>for(int i = 0; i < meshNum; ++i) {</div><div><span style="white-space:pre-wrap">            </span>double* temp = m_SkullMesh->GetOutput()->GetPoint(i);</div><div><span style="white-space:pre-wrap">              </span>skullTemplate[3*i] = temp[0];</div><div><span style="white-space:pre-wrap">            </span>skullTemplate[3*i+1] = temp[1];</div><div><span style="white-space:pre-wrap">          </span>skullTemplate[3*i+2] = temp[2];</div><div><span style="white-space:pre-wrap">  </span>}</div></div><div><br></div><div>But I think it should have a better way to avoid the copy and get the data pointer directly. Can you give me some suggestion? Thank you!</div><div><br></div><div>Best,</div><div>Lin</div></div></blockquote><div><br></div></span><div>Again, please post compilable code. My first guess would be that you did not update the reader before using the data you are expecting from GetOutput(). Try adding a m_SkullMesh->Update() before the block of code you've posted.<span class="HOEnZb"><font color="#888888"><br><br></font></span></div><span class="HOEnZb"><font color="#888888"><div>David<br></div></font></span></div></div></div>
</blockquote></div><br></div>