<DIV id=RTEContent> <DIV id=RTEContent>hello everyone, </DIV> <DIV> </DIV> <DIV><STRONG>Here is a brief guide on creating an image fro scratch in memory in VTK.</STRONG></DIV> <DIV> </DIV> <DIV>It wasnt obvious to me at the first look, but finally it dint take much time to figure it out....</DIV> <DIV> </DIV> <DIV>I am sure there would be many other ways to do this.............But here is the way i did it......... </DIV> <DIV> </DIV> <DIV>If anyone knows any alternative ways, please to add them to this thread. I know you could also do it with vtkImageCache and vtkStrcuturePoints.</DIV> <DIV> </DIV> <DIV>Here is how i solved the problem:</DIV> <DIV> </DIV> <DIV>vtkImageData is the basic data representation form for images in VTK.</DIV> <DIV> </DIV> <DIV>So if you want to create an image from scratch, you create an object of the vtkImageData.</DIV> <DIV> </DIV> <DIV>Set the image parameters first as shown in the code below. For
example, If you want an RGB image set the number of scalar components to be 3.</DIV> <DIV> </DIV> <DIV>Then call allocate scalars which allocates the scalars of the PointData of vtkImageData is also derived from vtkDataSet it inherits the basic structure of a VTK data set. </DIV> <DIV> </DIV> <DIV>Then you set the scalar values as needed.</DIV> <DIV> </DIV> <DIV>Below is a small snippet of code that does it. </DIV> <DIV> </DIV> <DIV>**************************************************************************************************</DIV><FONT size=2> <div> </div> <div>vtkImageData *pZImage = vtkImageData::New();</div> <div>pZImage->SetExtent( 0 , wx , 0 , wy , 0 , 0 );</div> <div>pZImage->SetOrigin( 0.0 , 0.0 , 0.0 );</div> <div>pZImage->SetSpacing( 1.0 , 1.0 , 1.0 );</div> <div>pZImage->SetScalarTypeToUnsignedChar();</div> <div>pZImage->SetNumberOfScalarComponents( 1 );</div>
<div>pZImage->AllocateScalars();</div> <div> </div> <div></FONT><FONT color=#0000ff size=2>for</FONT><FONT size=2>( </FONT><FONT color=#0000ff size=2>int</FONT><FONT size=2> i = 0 ; i < wx ; i++ )</div> <div>{</div> <BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"> <div></FONT><FONT color=#0000ff size=2>for</FONT><FONT size=2>( </FONT><FONT color=#0000ff size=2>int</FONT><FONT size=2> j = 0 ; j < wy ; j++ )</div> <div>{</div> <BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"> <div></FONT><FONT color=#0000ff size=2>int</FONT><FONT size=2> index = i * j;</FONT></div> <div><FONT size=2></FONT> </div> <div><FONT size=2>// get scalar pointer to current pixel</div> <div></FONT><FONT color=#0000ff size=2>unsigned</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>char</FONT><FONT size=2> *zPtr = (</FONT><FONT color=#0000ff size=2>unsigned</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>char</FONT><FONT size=2> *) pZImage->GetScalarPointer( i , j , 0
);</FONT></div> <div><FONT size=2></FONT> </div> <div><FONT size=2>// set scalar value accordingly</div> <div>*zPtr = 128; </div> <div> </div></BLOCKQUOTE> <div dir=ltr>} </div></BLOCKQUOTE> <div>}</div> <DIV></FONT> </DIV> <DIV>*************************************************************************************************</DIV> <DIV> </DIV> <DIV>Regards,</DIV> <DIV> </DIV> <DIV>Deepak Roy<BR></DIV></DIV><p>
        
                <hr size=1>Yahoo! Shopping<br>
Find Great Deals on Holiday Gifts at <a href="http://us.rd.yahoo.com/mail_us/footer/shopping/*http://shopping.yahoo.com/;_ylc=X3oDMTE2bzVzaHJtBF9TAzk1OTQ5NjM2BHNlYwNtYWlsdGFnBHNsawNob2xpZGF5LTA1
">Yahoo! Shopping</a>