[vtkusers] render 2D files into 3D
Audi
audi2006 at singnet.com.sg
Wed Mar 21 05:56:52 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)=20
{=20
GetDocument()->Cleanup();
CWaitCursor *cursor;
CString FileName;
unsigned char *Image;
unsigned short *Image2;
int Number=3D1;
bool ImageFlag=3Dfalse;
bool ImageFlag2=3Dfalse;
=20
cursor=3Dnew CWaitCursor;=20
CFileDialog filedialog(TRUE,"*.raw",NULL,NULL,"Raw Data File(*.raw) =
|*.raw||",NULL);
=20
if(filedialog.DoModal()=3D=3DIDCANCEL)
return FALSE;
=20
delete cursor;
cursor=3DNULL;
cursor=3Dnew CWaitCursor;
=20
FILE *fin;
=20
fin=3Dfopen(filedialog.GetFileName(),"rb");
=20
if(fin=3D=3DNULL)
{
AfxMessageBox("I was not able to open the file...");
return FALSE;
}
FileName=3Dfiledialog.GetFileName();
CInfoDialog datainfo;
if(datainfo.DoModal()=3D=3DIDCANCEL)
return FALSE;
if((*StructuredPoints)!=3DNULL)
{
(*StructuredPoints)->Delete();
(*StructuredPoints)=3DNULL;
}
=20
(*StructuredPoints)=3DvtkStructuredPoints::New();
=20
if(datainfo.m_ByteCount=3D=3D1)
{
(*StructuredPoints)->SetScalarType(VTK_UNSIGNED_CHAR);
Image=3Dnew unsigned =
char[datainfo.m_XDim*datainfo.m_YDim*datainfo.m_ZDim];
ImageFlag=3Dtrue;
}
else
{
(*StructuredPoints)->SetScalarType(VTK_UNSIGNED_SHORT);
Image2=3Dnew unsigned =
short[datainfo.m_XDim*datainfo.m_YDim*datainfo.m_ZDim];
ImageFlag2=3Dtrue;
}
=20
=
(*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!=3Ddatainfo.m_ZDim)
{
if(datainfo.m_ByteCount=3D=3D1)
{=20
fread(Image,1,datainfo.m_XDim*datainfo.m_YDim,fin);
fclose(fin);
=20
vtkScalars =
*scalars=3D(*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=3DNumber-1;k<Number;k++)
for(j=3D0;j<datainfo.m_YDim;j++)
for(i=3D0;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
{ =20
fread(Image2,2,datainfo.m_XDim*datainfo.m_YDim,fin);
fclose(fin);
vtkScalars =
*scalars=3D(*StructuredPoints)->GetPointData()->GetScalars();
scalars->SetDataType(VTK_UNSIGNED_SHORT);
scalars->Allocate(datainfo.m_XDim*datainfo.m_YDim*datainfo.m_ZDim);
=20
int i,j,k;
for(k=3DNumber-1;k<Number;k++)
for(j=3D0;j<datainfo.m_YDim;j++)
for(i=3D0;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]);
}
}
=20
if(filedialog.DoModal()=3D=3DIDCANCEL)
return FALSE;
fin=3Dfopen(filedialog.GetFileName(),"rb");
=20
if(fin=3D=3DNULL)
{
AfxMessageBox("I was not able to open the file...");
return FALSE;
}
=20
Number=3DNumber+1;
}
(*StructuredPoints)->Modified();
delete cursor;
cursor=3DNULL;
cursor=3Dnew CWaitCursor;
=20
if (ImageFlag=3D=3Dtrue)
delete [] Image;
if (ImageFlag2=3D=3Dtrue)
delete [] Image2;
=20
cursor->Restore();
delete cursor;
=20
return TRUE;
}
------=_NextPart_000_0022_01C0B165
More information about the vtkusers
mailing list