[vtkusers] problem with execute method

thomas thomas at cs.uno.edu
Wed Jun 25 12:23:38 EDT 2003


hi everybody

i have a problem with the Execute method of my class. If i call it directly in a Tcl script, there is no problem but if I call via a write method (look at the script below) it doesn't launch it and says that there is an error. I domn't understand why

in attached, I have put the files

thanks

thomas

*********************

package require vtklocal

vtkImageReaderDB inter
inter SetFileName tazc 
inter SetBeginX 1
inter SetBeginY 1
inter SetEndX 199
inter SetEndY 189
inter SetXResolution 1
inter SetYResolution 1
puts [[inter GetOutput] GetNumberOfPoints]
[inter GetOutput] Print

vtkTIFFWriter w
w SetInput [inter GetOutput]
w SetFileName "points.tiff"
w Write
*****************

void vtkImageReaderDB::Execute() {

 cout<<"debut reader"<<endl;
 PGconn     *conn;
    PGresult   *res;
 
    int         i,
                j;
    int         X,
  Y,
  OriX,
  OriY,
  DelX,
  DelY,
  NameOfImage;

    /*
     * begin, by setting the parameters for a backend connection if the
     * parameters are null, then the system will try to use reasonable
     * defaults by looking up environment variables or, failing that,
     * using hardwired constants
     */
    pghost = "xander.cs.uno.edu";              /* host name of the backend server */
    pgport = "8000";              /* port of the backend server */
    pgoptions = NULL;           /* special options to start up the backend
                                 * server */
    pgtty = NULL;               /* debugging tty for the backend server */
 
    dbName = "mydb";    /* change this to the name of your test
                                 * database */
 
 login = "thomas";
 pass = "fthomas123";

    /* make a connection to the database */
    conn = PQsetdbLogin(pghost, pgport, pgoptions, pgtty, dbName, login, pass);

    /*
     * check to see that the backend connection was successfully made
     */
    if (PQstatus(conn) == CONNECTION_BAD)
    {
        fprintf(stderr, "Connection to database '%s' failed.\n", dbName);
        fprintf(stderr, "%s", PQerrorMessage(conn));
        PQfinish(conn);
    }


    /* start a transaction block */
    res = PQexec(conn, "BEGIN");
    if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
    {
        fprintf(stderr, "BEGIN command failed\n");
        PQclear(res);
        PQfinish(conn);
    }
 

    /*
    * should PQclear PGresult whenever it is no longer needed to avoid
    * memory leaks
    */
    PQclear(res);

    /*
    * reading information concerning the image in GENERAL TABLE
    */
 char lecture[70];
 j  = sprintf( lecture, "%s", "DECLARE mycursor BINARY CURSOR FOR SELECT * FROM taz WHERE ImageName='");
 j += sprintf( lecture + j, "%s", FileName);
 j += sprintf( lecture + j, "%s","'");

   res = PQexec(conn,lecture);
    if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) {
        fprintf(stderr, "DECLARE CURSOR command failed\n");
        PQclear(res);
        PQfinish(conn);
    }
    PQclear(res);
 
    res = PQexec(conn, "FETCH ALL in mycursor");
    if (!res || PQresultStatus(res) != PGRES_TUPLES_OK) {
        fprintf(stderr, "FETCH ALL command didn't return tuples properly\n");
        PQclear(res);
        PQfinish(conn);
    }

 NameOfImage = PQfnumber(res, "ImageName");
 X = PQfnumber(res, "NumOfX");
 Y = PQfnumber(res, "NumOfY");
 OriX = PQfnumber(res, "OriginX");
 OriY = PQfnumber(res, "OriginY");
 DelX = PQfnumber(res, "DeltaX");
 DelY = PQfnumber(res, "DeltaY");


 int        Xval;
 int        Yval;
 float      OriXval;
 float      OriYval;
 float      DelXval;
 float      DelYval;
 char    *Nameval;

 i=0;

 /* we hard-wire this to the fields we know about */
 Nameval = PQgetvalue(res, i, NameOfImage);
 Xval = *(int *) PQgetvalue(res, i, X);
 Yval = *(int *) PQgetvalue(res, i, Y);
 OriXval = *(float *) PQgetvalue(res, i, OriX);
 OriYval = *(float *) PQgetvalue(res, i, OriY);
 DelXval = *(float *) PQgetvalue(res, i, DelX);
 DelYval = *(float *) PQgetvalue(res, i, DelY);

//writing the values on screen
 cout<<Nameval<<endl;
 printf("x = %d\n", Xval);
 printf("y = %d\n", Yval);
 printf("OriX = %f\n", OriXval);
 printf("OriY = %f\n", OriYval);
 printf("DelX = %f\n", DelXval);
 printf("DelY = %f\n", DelYval);


 /* close the cursor */
 res = PQexec(conn, "CLOSE mycursor");
 PQclear(res);

 //initializing a vtkImageData
 int DimX = Xval/XResolution;
 int DimY = Yval/YResolution;
 float DeltaX = DelXval * (XResolution);
 float DeltaY = DelYval * (YResolution);

cout<<DimX<<" "<<DimY<<" "<<DeltaX<<" "<<DeltaY<<endl;

 vtkImageData *sp = vtkImageData::New();
 sp->SetDimensions(DimX, DimY, 1);
 sp->SetOrigin(OriXval, OriYval, 0);
 sp->SetSpacing(DeltaX, DeltaY, 0);
 sp->SetScalarTypeToUnsignedChar();


 this->GetOutput()->SetDimensions(DimX, DimY, 1);
 this->GetOutput()->SetOrigin(OriXval, OriYval, 0);
 this->GetOutput()->SetSpacing(DeltaX, DeltaY, 0);
 this->GetOutput()->SetScalarTypeToUnsignedChar();



 //read the z value
 float *readValue;

 for (i = BeginY; i <= EndY; i = i + YResolution) {

  j  = sprintf( lecture, "%s", "DECLARE mycursorb BINARY CURSOR FOR SELECT * FROM "); //changer le select * en select juste ce qui faut????
  j += sprintf( lecture + j, "%s", Nameval);
  j += sprintf( lecture + j, "%s", " WHERE c0=");
  j += sprintf( lecture + j, "%d", i);
 
  res = PQexec(conn,lecture);
  if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) {
         fprintf(stderr, "DECLARE CURSOR command failed\n");
         PQclear(res);
         PQfinish(conn);
  }
  PQclear(res);

  res = PQexec(conn, "FETCH ALL in mycursorb");
     if (!res || PQresultStatus(res) != PGRES_TUPLES_OK) {
         fprintf(stderr, "FETCH ALL command didn't return tuples properly\n");
         PQclear(res);
         PQfinish(conn);
  }
  
cout<<i<<endl;

  //put the value into the scalar field of the vtkImageData
  for (j = BeginX; j <= EndX; j = j + XResolution) {
   unsigned char* pixel = (unsigned char*) sp->GetScalarPointer(j-1,i-1,0);
   readValue = (float *) PQgetvalue(res, 0, j);
   *pixel = (unsigned char) *readValue;
   unsigned char* pixelb = (unsigned char*) this->GetOutput()->GetScalarPointer(j-1,i-1,0);
   *pixelb = (unsigned char) *readValue;
  }

 
  /* close the cursor */
  res = PQexec(conn, "CLOSE mycursorb");
  PQclear(res);

 }

 //creating an image

 vtkTIFFWriter *tiff = vtkTIFFWriter::New();
 tiff->SetFileName("taz.tif");
 tiff->SetInput(sp);
 tiff->Write();
 cout<<tiff->GetFileName()<<endl;

 
 /* commit the transaction */
 res = PQexec(conn, "COMMIT");
 PQclear(res);
 
 /* close the connection to the database and cleanup */
 PQfinish(conn);


}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20030625/e8b86953/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: interpB.tcl
Type: application/octet-stream
Size: 492 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20030625/e8b86953/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vtkImageReaderDB.cxx
Type: application/octet-stream
Size: 9383 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20030625/e8b86953/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vtkImageReaderDB.h
Type: application/octet-stream
Size: 3427 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20030625/e8b86953/attachment-0002.obj>


More information about the vtkusers mailing list