[vtkusers] Errors using vtkCriticalSection

Tim Soper tim_d_soper at yahoo.com
Mon Jun 25 17:01:52 EDT 2007


Hi-
    I am having a lot of trouble with an application I am developing for displaying real-time tracking data. I am using Qt (specifically the QVTKWidget) to display the position and orientation of an electromagnetic sensor.  To do this I created a tracker class (vtk3DTracker) which continually reads a stream of position data in a separate thread. At each retrieval, a call to AdvanceStream( ) is made (see below). When accessing the hardware, a MutexLock is used from vtkSimpleCriticalSection.  This works just fine. To display the position of the sensor on the QVTKWidget, I create a series of vtkActors whose position and orientation are directly controlled by vtk3DTracker class.  Thus after unlocking the Mutex in the AdvanceStream( ) method, I call a function UpdateActors( ) (not shown) which simply sets the actors position and orientation to that of the sensor as read by the hardware. This also works fairly well, however, when rotating or zooming, I often receive access
 violation errors.  In debug mode, these errors break at code within the vtkAbstractTransform, vtkHomogeneousTransform, or vtkCriticalSection code. I do not know why or how to fix it. Is this an incorrect method of updating actors? Am I using the vtkCriticalSection / vtkSimpleCriticalSection class incorrectly? Could really use the help.

//----------------------------------------------------------------------------
//constructor
vtk3DTracker::vtk3DTracker()
{
    //initialize states
    this->isInitialized = false;
    this->isStreaming = false;
    this->isWritingToFile = false;

    this->StreamSize = 1;
    this->NumberOfComponents = 7;
    this->StreamRate = 30;

    //set up the stream thrad
    this->StreamThreader = vtkMultiThreader::New();
    this->StreamThreadId = -1;

    //create critical section mutex
    this->StreamMutex = vtkSimpleCriticalSection::New();

    this->NumberOfStreams = 0;
    this->StreamArray = NULL;
    this->StreamIndex = 0;
    this->SetNumberOfStreams(1);

    isActorConnectedToStream = NULL;

}

..
..
..

//--------------------------------------------------------------------
//read in the sensor data
void vtk3DTracker::AdvanceStream()
{
    //lock sensor data
    StreamMutex->Lock();
    
    int error;
    bool isStamped = false;
    double timestamp;
    for(int isensor = 0; isensor < systemConfig.numberSensors; isensor++)
    {
        //don't read unattached sensors
        if(!sensorConfig[isensor].attached)
            continue;

        //get sensor position from hardware
        if( (error = GetAsynchronousRecord(isensor,&sensorRecord[isensor], 
            sizeof(DOUBLE_POSITION_ANGLES_TIME_Q_RECORD))) != BIRD_ERROR_SUCCESS )
        {
            GetErrorText( error, errorMsg, errorMsgBufferSize, messageType );
            vtkErrorMacro(<< errorMsg);
            return;
        }

        //set the time stamp to the system time so that it syncs with captured video
        if(!isStamped)
        {
            timestamp = vtkTimerLog::GetUniversalTime();
            isStamped = true;
        }
        sensorRecord[isensor].time = timestamp;

        if( isWritingToFile )
            WriteRecordToFile();

        this->Modified();

        //unlock sensor data
        StreamMutex->Unlock();

        //finally update the actors which represent the sensors
        UpdateActors();        

    }
}
 
Tim Soper 
Research Assistant
University of Washington
Department of Bioengineering 
Box 352142





       
____________________________________________________________________________________
Choose the right car based on your needs.  Check out Yahoo! Autos new Car Finder tool.
http://autos.yahoo.com/carfinder/



More information about the vtkusers mailing list