Hi,
I try to create a clip desciptor from a solid which is a projected surface. I create my solid like this :
points[0].x = xmin; points[0].y = ymin; points[0].z = zmin; points[1].x = xmax; points[1].y = ymin; points[1].z = zmin; points[2].x = xmax; points[2].y = ymax; points[2].z = zmin; points[3].x = xmin; points[3].y = ymax; points[3].z = zmin; points[4].x = xmin; points[4].y = ymin; points[4].z = zmin; if (mdlShape_create( &elmSurf, NULL, points, 5, 0 )!=SUCCESS) { AffMsg( 200, 1, ">>> Erreur à la création de la shape de clip\n" ); } mdlElmdscr_new( &elDescrP, NULL, &elmSurf ); pt1.x = pt1.y = 0.0; pt1.z = zmin; pt2.x = pt2.y = 0.0; pt2.z = zmax; if (mdlSurface_project( elDescrClipP, elDescrP, &pt1, &pt2, NULL )!=SUCCESS) { if( elDescrP ) mdlElmdscr_freeAll( &elDescrP ); AffMsg( 200, 1, ">>> Erreur à la création de la surface de projection de clip\n" ); throw std::exception("Erreur à la création de la surface de projection de clip"); } //On l'ajoute au fichier mdlElmdscr_add(*elDescrClipP); if( elDescrP ) mdlElmdscr_freeAll( &elDescrP );
Note that I don't add the element to the model.
Then I create the clipping descriptor like this :
//Calcul du clipdescripteur if ( mdlClip_fromElement ( &clipDescr,clipElmDescr,FALSE,NULL, -1 )!=SUCCESS ) throw std::exception("Impossible de definir le clip a utilisé pour le lot");
After that, when I check on an element if it's Inside the clipping descriptor like this :
if( mdlClip_isElemInside( &overlap, edP, opts->clipDescripteur, tcb->fenvw, TRUE ) != 0 ) {
It return 0 (that mean element is not Inside) but I'm sure that the element is inside.
Note :
- I don't understand why there is an argument for the view number (What is the purpose of this parameter, beacause of the clip descriptor is a volume).
- The view tcb->fenvw is "0" and this view is isometric
We can't see all your variable declarations, but this statement is suspicious:
if (mdlSurface_project( elDescrClipP, elDescrP, &pt1, &pt2, NULL ) != SUCCESS)
That function allocates memory and requires the address-of an MSElementDescr*, which you should use like this:
the address-of an MSElementDescr*
MSElementDescr* pProjection = NULL; if (mdlSurface_project (&pProjection, elDescrP, &pt1, &pt2, NULL ) != SUCCESS) ... mdlElmdscr_freeAll (&pProjection);
Regards, Jon Summers LA Solutions
I pass the elDescrClipP to a function, the entire code is :
/*==============================================================================*/ int createClipElmDesc ( MSElementDescr **elDescrClipP, double xchevauchement, /* I x chevauchement entre lot */ double zchevauchement, /* I z chevauchement entre lot */ LOT *curLotP /* I structure lot */ ) /*============================================================================== | | Retour: SUCCESS pas de problème | ERROR | | Description: Créer un elementdescripteur definissant le clip du lot | | /******************************************************************************/ { double zmin, zmax; double xmin, xmax; double ymin, ymax; DPoint3d pt1, pt2; DPoint3d points[5]; MSElementDescr *elDescrP; MSElement elmSurf; //#define DEBUG #ifdef DEBUG AffMsg( 200, 1, "GenerateClipElement\n\n"); #endif xmin = curLotP->range.org.x - ( xchevauchement * mdlModelRef_getUorPerMaster( MASTERFILE ) ); xmax = curLotP->range.end.x + ( xchevauchement * mdlModelRef_getUorPerMaster( MASTERFILE ) ); ymin = curLotP->range.org.y; ymax = curLotP->range.end.y; zmin = curLotP->range.org.z - ( zchevauchement * mdlModelRef_getUorPerMaster( MASTERFILE ) ); zmax = curLotP->range.end.z + ( zchevauchement * mdlModelRef_getUorPerMaster( MASTERFILE ) ); memcpy( &G_rangeLot.org, &curLotP->range.org, sizeof( Dpoint3d ) ); memcpy( &G_rangeLot.end, &curLotP->range.end, sizeof( Dpoint3d ) ); #ifdef DEBUG sprintf( msg, ">>> xmin=%lf xmax=%lf ymin=%lf ymax=%lf zmin=%lf zmax=%lf ", xmin, xmax, ymin, ymax, zmin, zmax ); AffMsg( 200, 1, msg ); #endif points[0].x = xmin; points[0].y = ymin; points[0].z = zmin; points[1].x = xmax; points[1].y = ymin; points[1].z = zmin; points[2].x = xmax; points[2].y = ymax; points[2].z = zmin; points[3].x = xmin; points[3].y = ymax; points[3].z = zmin; points[4].x = xmin; points[4].y = ymin; points[4].z = zmin; if (mdlShape_create( &elmSurf, NULL, points, 5, 0 )!=SUCCESS) { AffMsg( 200, 1, ">>> Erreur à la création de la shape de clip\n" ); } mdlElmdscr_new( &elDescrP, NULL, &elmSurf ); pt1.x = pt1.y = 0.0; pt1.z = zmin; pt2.x = pt2.y = 0.0; pt2.z = zmax; if (mdlSurface_project( elDescrClipP, elDescrP, &pt1, &pt2, NULL )!=SUCCESS) { if( elDescrP ) mdlElmdscr_freeAll( &elDescrP ); AffMsg( 200, 1, ">>> Erreur à la création de la surface de projection de clip\n" ); throw std::exception("Erreur à la création de la surface de projection de clip"); } if( elDescrP ) mdlElmdscr_freeAll( &elDescrP ); return SUCCESS; }
Thanks
Since you've posted that adding your clip element to the model and setting it up as the reference clip boundary works, I'll assume that your clip element has been created correctly.
The main difference between using mdlClip_fromElement vs. mdlClip_getRefBoundary then is the reference transform. Since you appear to be testing elements from a reference model against your ClipDescr, if it's not a coincident attachment (i.e. reference to master transform isn't identity) then you need to take the reference transform into account when setting up your clip descriptor so that the ClipDescr and the elements you are testing are in same coordinate system.
-B