mdlClip_fromElement with a solid

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

  • Which version (e.g. 10.x.y.z) are you using?

    Unknown said:
    I don't understand why there is an argument for the view number

    Because a clip descriptor is most usually created from a fence, and a fence is view-dependent.

     
    Regards, Jon Summers
    LA Solutions

  • Sorry I forget to mention the version which is in my case probably very important because it's a very old version. I use the 08.05.01.25

  • I continu to check how it's works or why it doesn't works as I expect.

    If i replace 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");

    by this :

        //Ajout de clip au fichier
    	ULong posClipDescripteur = mdlElmdscr_add(clipElmDescr);
    	mdlElmdscr_display( clipElmDescr, MASTERFILE, NORMALDRAW );
    
    	refFileP = mdlRefFile_getInfo( modelRefP );
    	if( refFileP != NULL ) {
    		ElementID clipID = mdlElement_getID( &clipElmDescr->el );
    		refFileP->clip.clipElement = clipID;
    	}
    
    	if ( mdlClip_getRefBoundary ( &clipDescr,modelRefP, tcb->fenvw )!=SUCCESS ) throw std::exception("Impossible de definir le clip a utilisé pour le lot");
    	
    	//Scan a reference file with scan argument containing clipdescriptor
    	//Do some stuff
    	mdlClip_isElemInside( &overlap, edP, opts->clipDescripteur, tcb->fenvw, TRUE ) != 0 ) {
    	//Do some stuff
    	//End of Scan
    	
    	if (clipDescr) mdlClip_free(&clipDescr);
    	mdlElement_undoableDelete( NULL, posClipDescripteur, TRUE );
    	
    	

    Then all seems to works correctly.

    In some case I could use this solution because I need to process a reference file but in some other case, I need to process object that I create and I don't have any reference file to clip.

  • Unknown said:
    I use the 08.05.01.25

    Which version of Visual Studio are you using?

     
    Regards, Jon Summers
    LA Solutions

  • I use visual studio 2010 express but on the compilation process, I define the path to the bin folder of VC98.

    I develop "in native code".

  • Unknown said:
    I use visual studio 2010

    For MicroStation V8 2004 Edition you should use Viz Studio 6.  See this table of versions.

    If you use an incompatible version of Viz Studio, you may be either compiling a mis-matched binary, linking on incorrect word boundaries, or a combination of those, with perhaps other problems thrown in to the mix.

     
    Regards, Jon Summers
    LA Solutions

  • Thanks but in my compile process (makefile) I load this environment %VC98BIN%\vcvars32.bat, where %VC98BIN% is the bin folder of Visual Studio 6 so I think it's OK?

  • 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:

    MSElementDescr* pProjection = NULL;
    if (mdlSurface_project (&pProjection, elDescrP, &pt1, &pt2, NULL ) != SUCCESS)
    ...
    mdlElmdscr_freeAll (&pProjection);
    

     
    Regards, Jon Summers
    LA Solutions

  • Hi,

    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