PDA

View Full Version : Automatically detecting field connected to grid


francis
24th August 2011, 18:49
Hi,

I have a tetragrid with a scalar field connected to it. I am creating a compute module and I want to automatically detect if a suitable field is connected when a grid is connected. I tried:

void MyPackage::update()
{
HxTetraGrid* grid = (HxTetraGrid*) this->portData.source();

HxTetraScalarField3* field = 0; //
for (int i=0; i<grid->downStreamConnections.size(); i++) {
HxTetraScalarField3* tmp = (HxTetraScalarField3*) grid->downStreamConnections[i];
if ( tmp->isOfType(HxTetraScalarField3::getClassTypeId()) ) {
field = tmp;
break;
}
}
}

However, doing tmp->isOfType(HxTetraScalarField3::getClassTypeId()) always returns 0. I've tried casting the downStreamConnection[i] as as a HxTetraField3, HxField3, HxTetraData, and HxObject, but isOfType always returns 0. Should this be a dynamic cast instead?

For now, I've just added a second connection port to the module for a HxTetraScalarField3.

Thanks,

Francis
--
Windows XP 64-bit, Avizo 6.3.0

barbis
10th January 2012, 10:09
Hello!

This one works for me in AMIRA enviroment, you could easily adjust it to your tetragrids:

h = surface -> getNumPoints();

theMsg->printf("ga1");
theWorkArea->busy();
// Search for surfacescalarfields connectected to surface

for (i=0; i<surface->downStreamConnections.size(); i++)
{
HxSurfaceScalarField* field = (HxSurfaceScalarField*) portData.source() -> downStreamConnections[i] -> object();

if (field->isOfType(HxSurfaceScalarField::getClassTypeId()))
{
z = field -> nValues() ;
if (z == h) { theMsg->printf("Found the curvature field!"); break;}
}

}
if(z==0){ theMsg->printf("No connected fields found!"); return;}


HxSurfaceScalarField* field = (HxSurfaceScalarField*) portData.source() -> downStreamConnections[i] -> object();

// Get the curvature values
float* v = field -> dataPtr();




hope this helps!

toni

pwestenb
11th January 2012, 11:05
Dear Francis,

I think Toni already gave the right answer, but to be sure just find below some code that should do the job:

HxTetraGrid* grid = (HxTetraGrid*) this->portData.source();
if (!grid) {
theMsg->printf("please connect a tretra grid to this module");
return;
}
HxTetraScalarField3* field = 0;
for (int i=0; i<grid->downStreamConnections.size(); i++) {
theMsg->printf("object %i\n",i);
HxTetraScalarField3* tmp = (HxTetraScalarField3*) grid->downStreamConnections[i]->object();
if ( tmp->isOfType(HxTetraScalarField3::getClassTypeId()) ) {
field = tmp;
theMsg->printf("Found a HxTetraScalarField3 connection at index %i\n",i);
break;
}
}
Best Regards,
Peter