[Insight-users] itkMesh object in a static library as global variable

Quan Chen quanchen at gmail.com
Thu Oct 27 18:24:22 EDT 2005


I was trying to follow the applications example itkfilterlib.  In that
example, the smart pointer to input and output image, as well as the smart
pointer to filter, are declared as a global variable.  SetReferenceCount(2)
was called to ensure the persistance of the filter and image data.  
First, I don't understand why we have to reset the referenceCount. Since the
pointer are global variable, it should still exist after the function
returns.  
 
Now, I want to build a lib involves itkMesh manipulation.  According to my
understanding, we can't pass a pointer containing the points to the itkMesh
object like the example did on itkImage.  So we have to actually construct
the itkMesh object as the itk software guide illustrates, right?  Now do we
have to set reference count in this case? 
 
I may call the itkMesh construction routine several times to create
different input mesh.  I guess I need to make sure the previous mesh has
been destroyed.  Will SetReferenceCount(0) make sure that it will be
destroyed or we can call initialize() to do that?  
 
#include <itkMesh.h>
 
typedef  itk::Mesh<g_internalDataType>     g_MeshType;
 
g_MeshType::Pointer g_InputMesh;
 
mylib::mylib()
{
  g_InputMesh = g_MeshType::New();
  g_InputMesh->SetReferenceCount(2);  //necessary?
}
 
void mylib::CreateInputMesh(int& _nf, Vector<long, 3>* tricells, int& _np,
Vector<float, 3>* points)
{
  g_InputMesh->SetReferenceCount(0);
  g_InputMesh = g_MeshType::New(); 
// or
 g_InputMesh->Initialize();
// construct g_InputMesh
...
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20051027/d25a0eee/attachment.htm


More information about the Insight-users mailing list