[vtkusers] structured point to render few 2D
Audi
audi2006 at singnet.com.sg
Tue Mar 20 04:47:04 EST 2001
Hi,
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,
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,datainfo.m_ZDim);
(*StructuredPoints)->SetSpacing(datainfo.m_XScale,datainfo.m_YScale,datainfo.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_XDim)+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;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20010320/7c6c4fbf/attachment.htm>
More information about the vtkusers
mailing list