[vtkusers] render 2D files into 3D

Audi audi2006 at singnet.com.sg
Mon Mar 26 05:05:47 EST 2001


> Hi,
> Anybody can help me now?(because I need this urgently)
> I used vtkStructuredPoints to render few 2D data to form 3D
> instead of using volume rendering.
> But I have problem to render it.
> This is the function for rendering few 2D files into 3D,=20
> can anybody find what is the problem with my function?I'm stuck.
> I hope somebody can help me to find it.
>
> 1. m_XDim,m_YDim are file dimensions
> 2. m_ZDim is the number of 2D files that has been read
> 3. Number is the counter to count how many files that has been read
> 4. m_XScale,m_YScale,m_ZScale are the file spacing
>
> My program is reading the 2D file one by one, every time reading one =
> file it will
> store it into vtkStructuredPoints. I also check with the =
> vtkVolumeReader, it seems
> correct, but my prog only can view 2D instead of 3D. It seems the =
> storing part
> not succesful, but I can't find why, so anybody can find it?
>
> Thanks a lot,
> Audi
>
> BOOL CPointsVisualizationView::LoadRawDataMul(vtkStructuredPoints =
> **StructuredPoints)
> {
>  GetDocument()->Cleanup();
>
>  CWaitCursor *cursor;
>  CString FileName;
>  unsigned char *Image;
>  unsigned short *Image2;
>  int Number=1;
>  bool ImageFlag=false;
>  bool ImageFlag2=false;

>  cursor=new CWaitCursor;
> CFileDialog filedialog(TRUE,"*.raw",NULL,NULL,"Raw Data File(*.raw)
> |*.raw||",NULL);
>
>  if(filedialog.DoModal()=IDCANCEL)
>  return FALSE;
>
>  delete cursor;
>  cursor=NULL;
>  cursor=new CWaitCursor;
>
>  FILE *fin;
>
>  fin=fopen(filedialog.GetFileName(),"rb");
>
>  if(fin=NULL)
>  {
>  AfxMessageBox("I was not able to open the file...");
>  return FALSE;
>  }
>
>  FileName=filedialog.GetFileName();
>  CInfoDialog datainfo;
>  if(datainfo.DoModal()=IDCANCEL)
>   return FALSE;
>
>  if((*StructuredPoints)!=NULL)
>  {
>  (*StructuredPoints)->Delete();
>  (*StructuredPoints)=NULL;
>  }
>
>  (*StructuredPoints)=vtkStructuredPoints::New();
>
>  if(datainfo.m_ByteCount=1)
>   {
>    (*StructuredPoints)->SetScalarType(VTK_UNSIGNED_CHAR);
>    Image=new unsigned =
> char[datainfo.m_XDim*datainfo.m_YDim*datainfo.m_ZDim];
>    ImageFlag=true;
>   }
>   else
>   {
>    (*StructuredPoints)->SetScalarType(VTK_UNSIGNED_SHORT);
>    Image2=new unsigned =
> short[datainfo.m_XDim*datainfo.m_YDim*datainfo.m_ZDim];
>    ImageFlag2=true;
>   }
>
>
> (*StructuredPoints)->SetDimensions(datainfo.m_XDim,datainfo.m_YDim,datain=
> fo.m_ZDim);
>  =
> (*StructuredPoints)->SetSpacing(datainfo.m_XScale,datainfo.m_YScale,datai=
> nfo.m_ZScale);
>
>  (*StructuredPoints)->AllocateScalars();
>
>  while (Number!=datainfo.m_ZDim)
>  {
>   if(datainfo.m_ByteCount=1)
>   {
>    fread(Image,1,datainfo.m_XDim*datainfo.m_YDim,fin);
>    fclose(fin);
>
>    vtkScalars =
> *scalars=(*StructuredPoints)->GetPointData()->GetScalars();
>    scalars->SetDataType(VTK_UNSIGNED_CHAR);
>    scalars->Allocate(datainfo.m_XDim*datainfo.m_YDim*datainfo.m_ZDim);
>
>    int i,j,k;
>
>    for(k=Number-1;k<Number;k++)
>     for(j=0;j<datainfo.m_YDim;j++)
>      for(i=0;i<datainfo.m_XDim;i++)
>      {
>
> scalars->InsertScalar(k*(datainfo.m_YDim*datainfo.m_XDim)+j*(datainfo.m_X=
> Dim)+i,Image[k*(datainfo.m_YDim*datainfo.m_XDim)+j*(datainfo.m_XDim)+i]);=
>
>      }
>  }
>   else
>

>    fread(Image2,2,datainfo.m_XDim*datainfo.m_YDim,fin);
>    fclose(fin);
>
>    vtkScalars =
> *scalars=(*StructuredPoints)->GetPointData()->GetScalars();
>    scalars->SetDataType(VTK_UNSIGNED_SHORT);
>    scalars->Allocate(datainfo.m_XDim*datainfo.m_YDim*datainfo.m_ZDim);
>
>    int i,j,k;
>
>    for(k=Number-1;k<Number;k++)
>     for(j=0;j<datainfo.m_YDim;j++)
>      for(i=0;i<datainfo.m_XDim;i++)
>      {
>
> scalars->SetScalar(k*(datainfo.m_YDim*datainfo.m_XDim)+j*(datainfo.m_XDim=
> )+i,Image2[k*(datainfo.m_YDim*datainfo.m_XDim)+j*(datainfo.m_XDim)+i]);
>      }
>   }
>
>   if(filedialog.DoModal()=IDCANCEL)
>    return FALSE;
>
>   fin=fopen(filedialog.GetFileName(),"rb");
>
>   if(fin=NULL)
>   {
>    AfxMessageBox("I was not able to open the file...");
>    return FALSE;
>   }
>
>   Number=Number+1;
>  }
>
>  (*StructuredPoints)->Modified();
>
>  delete cursor;
>  cursor=NULL;
>  cursor=new CWaitCursor;
>
>
>  if (ImageFlag=true)
>   delete [] Image;
>  if (ImageFlag2=true)
>   delete [] Image2;
>
>  cursor->Restore();
>  delete cursor;
>
>  return TRUE;
> }
>
>
>
> ------=_NextPart_000_0022_01C0B165
>





More information about the vtkusers mailing list