From: Praveen Bhaniramka (praveenb++at++mrcoffee.engr.sgi.com)
Date: 06/10/2003 14:00:56
Hi Simone,
You seem to be using the operators new and delete to allocate and free
memory for the lookup table data. Performer uses a multiprocessed
execution model and so the data needs to be allocated from shared memory
arenas in order to ensure that the data is visible in the various
processes including the draw process. The default new and delete operators
allocate and free memory from the current process' address space.
For example, you will need to modify the following LOC
float *data = new float[2*256];
to
float *data = (float *)pfMalloc(2*256*sizeof(float));
pfMalloc will allocate the data from a Performer shared memory arena.
You can do the same thing for the deletion callback, where you should call
pfDelete to delete the data pointer.
Cheers,
Praveen
On Tue, 10 Jun 2003, Simone Herrmann wrote:
> Here the code. The class Volume is derived from pfVolume. It works in a
> Volumizer apllication. I even wrote the printLookupTable function for
> debugging and it prints the right table. There are no error messages on
> the console.
>
> #include "Volume.h"
>
> Volume::Volume()
> {
> }
>
> Volume::~Volume()
> {
> }
>
> void
> Volume::loadLutFile(const char* lutName)
> {
> vzParameterLookupTable* table = loadLookupTable(lutName);
> if(table == NULL)table = initLookupTable();
> getShape()->getAppearance()->setParameter("lookup_table", table);
>
> vzTMLUTShader *shader = new vzTMLUTShader();
> getShape()->getAppearance()->setShader(shader);
> }
>
> vzParameterLookupTable*
> Volume::initLookupTable()
> {
> vzParameterLookupTable* table;
>
> float* data = new float[2*256];
> for (int i = 0; i < 256; i++) {
> const float value = (float) i / (256 - 1);
> data[i * 2 + 0] = value; // luminance
> data[i * 2 + 1] = value; // alpha
> }
> table = new vzParameterLookupTable(256, data, VZ_FLOAT, VZ_LUMINANCE_ALPHA);
> table->addDeletionCallback(cleanupLookupTable, data);
>
> return table;
> }
>
> vzParameterLookupTable*
> Volume::loadLookupTable(const char* filename)
> {
> float* data;
> int width, tuple, size;
> vzTextureType dataType;
> vzExternalTextureFormat formatType;
> vzParameterLookupTable* table;
>
> ifstream stream(filename);
>
> if (!stream) {
> cerr
> << "UserInterface::loadLutFromFile: Could not read data from lut file "
> << filename
> << endl;
> return NULL;
> }
>
> // Buffer to read stream tokens
> char buf[1024];
>
> stream >> buf;
> width = atoi(buf);
>
> stream >> buf;
> tuple = atoi(buf);
>
> size = width*tuple;
>
> stream >> buf;
> if(strcmp(buf,"float")==0)dataType = VZ_FLOAT;
> else if(strcmp(buf,"ubyte")==0)dataType = VZ_UNSIGNED_BYTE;
> else
> {
> cerr << "LUT error: data type in lut file not implemented" << endl;
> return NULL;
> }
>
> data = new float[size];
> for(int i=0; i<size; i++)
> {
> stream >> buf;
> data[i] = atof(buf);
> }
>
> if(tuple == 1) formatType = VZ_LUMINANCE;
> else if(tuple == 2) formatType = VZ_LUMINANCE_ALPHA;
> else if(tuple == 4) formatType = VZ_RGBA;
> else
> {
> cerr << "LUT error: wrong size of tuples in lut file" << endl;
> delete(data);
> return NULL;
> }
>
> table = new vzParameterLookupTable(width, data, dataType, formatType);
>
> table->addDeletionCallback(cleanupLookupTable, data);
> return table;
> }
>
> void
> Volume::printLookupTable(const char* filename)
> {
> vzParameterLookupTable* testTable = (vzParameterLookupTable*) getShape()->getAppearance()->getParameter("lookup_table");
>
> static int h=0;
> int i,width;
>
> if(h==0){
> h=1;
> ofstream ostream(filename);
> float* test = (float*)testTable->getDataPtr();
> width = testTable->getWidth();
> ostream << width << endl;
> for(i=0; i<width; i++)
> {
> for(int j=0; j<4; j++)ostream << test[(4*i)+j];
> ostream << endl;
> }
> }
> }
>
> void
> Volume::cleanupLookupTable(vzObject * /* object */, void *data)
> {
> delete [] data;
> }
>
>
>
>
>
> Praveen Bhaniramka <praveenb++at++mrcoffee.engr.sgi.com> schrieb am 10.06.03 11:26:40:
> >
> > Hi Simone,
> >
> > Did you define the parameter "lookup_table" appropriately for the shape's
> > appearance? You will still need to do the LUT initialization and other
> > stuff that you had mentioned in your code snippet! Do you get any errors
> > printed on the console?
> >
> > - Praveen
> >
> > On Tue, 10 Jun 2003, Simone Herrmann wrote:
> >
> > > Hi Praveen,
> > >
> > > I tried this and now my volume volume is not visible any more.
> > > What happened?
> > >
> > > Praveen Bhaniramka <praveenb++at++mrcoffee.engr.sgi.com> schrieb am 09.06.03 18:44:52:
> > > >
> > > > Hi Simone,
> > > >
> > > > The various parameters attached to the shape's appearance are used by the
> > > > shader, which uses them to do the actual shading (in your case applying a
> > > > lookup table). So, adding new parameters will only have any effect if the
> > > > corresponding shader _uses_ these parameters.
> > > >
> > > > In short, update the shader for the shape's appearance to use the
> > > > TMLUTShader, which would then apply the lookup table.
> > > >
> > > > vzTMLUTShader *newShader = new vzTMLUTShader();
> > > > vol->getShape()->getAppearance()->setShader(newShader);
> > > >
> > > > Cheers,
> > > > Praveen
> > > >
> > > > On Mon, 9 Jun 2003, Simone Herrmann wrote:
> > > >
> > > > > Hi,
> > > > >
> > > > > How can I apply a lookup table to a volume in the pfVolume node?
> > > > >
> > > > > I tried:
> > > > >
> > > > > vzParameterLookupTable* myTable = myLoadLookupTable();
> > > > >
> > > > > pfVolume* vol = new pfVolume;
> > > > > vol->readFile("myVolume.vz");
> > > > > vol->getShape()->getAppearance()->setParameter("lookup_table", myTable);
> > > > >
> > > > > but the image still remains uncoloured.
> > > > >
> > > > > Thanks,
> > > > > Simone
> > > > > ______________________________________________________________________________
> > > > > UNICEF bittet um Spenden fur die Kinder im Irak! Hier online an
> > > > > UNICEF spenden: https://spenden.web.de/unicef/special/?mc=021101
> > > > >
> > > > > -----------------------------------------------------------------------
> > > > > List Archives, Info, FAQ: http://www.sgi.com/software/performer/
> > > > > Open Development Project: http://oss.sgi.com/projects/performer/
> > > > > Submissions: info-performer++at++sgi.com
> > > > > Admin. requests: info-performer-request++at++sgi.com
> > > > > -----------------------------------------------------------------------
> > > > >
> > > > >
> > > >
> > > > --
> > > > -----------------------------------------------------------------
> > > > Praveen Bhaniramka Member of Technical Staff (MTS)
> > > > praveenb++at++sgi.com Advanced Graphics Division
> > > > (650)933-1785 Silicon Graphics, Inc.
> > > > -----------------------------------------------------------------
> > >
> > >
> > > ____________________________________________________________________________
> > > Jetzt bei WEB.DE FreeMail anmelden = 1qm Regenwald schuetzen! Helfen
> > > Sie mit! Nutzen Sie den Serien-Testsieger. http://user.web.de/Regenwald
> > >
> > >
> >
> > --
> > -----------------------------------------------------------------
> > Praveen Bhaniramka Member of Technical Staff (MTS)
> > praveenb++at++sgi.com Advanced Graphics Division
> > (650)933-1785 Silicon Graphics, Inc.
> > -----------------------------------------------------------------
> >
> > -----------------------------------------------------------------------
> > List Archives, Info, FAQ: http://www.sgi.com/software/performer/
> > Open Development Project: http://oss.sgi.com/projects/performer/
> > Submissions: info-performer++at++sgi.com
> > Admin. requests: info-performer-request++at++sgi.com
> > -----------------------------------------------------------------------
> >
>
>
> ______________________________________________________________________________
> UNICEF bittet um Spenden fur die Kinder im Irak! Hier online an
> UNICEF spenden: https://spenden.web.de/unicef/special/?mc=021101
>
>
-- ----------------------------------------------------------------- Praveen Bhaniramka Member of Technical Staff (MTS) praveenb++at++sgi.com Advanced Graphics Division (650)933-1785 Silicon Graphics, Inc. -----------------------------------------------------------------
This archive was generated by hypermail 2b29 : Tue Jun 10 2003 - 14:02:29 PDT