Beispiel #1
0
/*! \fn MFImplicitMF MFIMFCreateSphere(double x,double y,double z,double R, MFErrorHandler e);
 *  \brief Creates an implicitly defined manifold for a 2-sphere embedded in 3-space, centered at (x,y,z) with
 *         radius R.
 *
 *  \param x The x coordinate of the center of the sphere
 *  \param y The y coordinate of the center of the sphere
 *  \param z The z coordinate of the center of the sphere
 *  \param R The radius.
 *  \param e An error handler.
 *  \returns An implicitly defined manifold.
 */
MFImplicitMF MFIMFCreateSphere(double x,double y,double z,double R, MFErrorHandler e)
 {
  static char RoutineName[]={"MFIMFCreateSphere"};
  MFImplicitMF sphere;
  MFNSpace space;
  double *data;

  sphere=MFIMFCreateBaseClass(3,2,"Sphere",e);

  space=MFCreateNSpace(3,e);
  MFIMFSetSpace(sphere,space,e);
  MFFreeNSpace(space,e);

  data=(double*)malloc(4*sizeof(double));

#ifndef MFNPOSAFETYNET
  if(data==NULL)
   {
    sprintf(MFSphereMFErrorHandlerMsg,"Out of memory, trying to allocate %d bytes",4*sizeof(double));
    MFSetError(e,12,RoutineName,MFSphereMFErrorHandlerMsg,__LINE__,__FILE__);
    MFErrorHandlerOutOfMemory(e);
    free(sphere);
    return NULL;
   }
#endif

  data[0]=x;
  data[1]=y;
  data[2]=z;
  data[3]=R;
  MFIMFSetData(sphere,(void*)data,e);
  MFIMFSetFreeData(sphere,MFFreeSphereData,e);
  MFIMFSetProject(sphere,MFProjectSphere,e);
  MFIMFSetTangent(sphere,MFTangentSphere,e);
  MFIMFSetR(sphere,-1.,e);
  MFIMFSetScale(sphere,MFScaleSphere,e);
  MFIMFSetWriteData(sphere,MFWriteSphereData,e);
  MFIMFSetProjectForSave(sphere,MFSphereProjectToSave,e);
  MFIMFSetProjectForDraw(sphere,MFSphereProjectToDraw,e);
  MFIMFSetProjectForBB(sphere,MFSphereProjectForBB,e);

  MFIMFSetVectorFactory(sphere,MFNVectorFactory,e);
  MFIMFSetMatrixFactory(sphere,MFNKMatrixFactory,e);

  return sphere;
 }
Beispiel #2
0
/*! \fn MFImplicitMF MFIMFCreateCircle(double x,double y,double R, MFErrorHandler e);
 *  \brief Creates an implicitly defined manifold for a circle embedded in the plane, centered at (x,y) with
 *         radius R.
 *
 *  \param x The x coordinate of the center of the circle
 *  \param y The y coordinate of the center of the circle
 *  \param R The radius.
 *  \param e An error handler.
 *  \returns An implicitly defined manifold.
 */
MFImplicitMF MFIMFCreateCircle(double x,double y,double R, MFErrorHandler e)
 {
  static char RoutineName[]={"MFIMFCreateCircle"};
  MFImplicitMF circle;
  MFNSpace space;
  double *data;

  circle=MFIMFCreateBaseClass(2,1,"Circle",e);

  space=MFCreateNSpace(2,e);
  MFIMFSetSpace(circle,space,e);
  MFFreeNSpace(space,e);

  data=(double*)malloc(3*sizeof(double));

#ifndef MFNOSAFETYNET
  if(data==NULL)
   {
    sprintf(MFCircleMFErrorHandlerMsg,"Out of memory, trying to allocate %d bytes",3*sizeof(double));
    MFSetError(e,12,RoutineName,MFCircleMFErrorHandlerMsg,__LINE__,__FILE__);
    free(circle);
    return NULL;
   }
#endif

  data[0]=x;
  data[1]=y;
  data[2]=R;
  MFIMFSetData(circle,data,e);
  MFIMFSetFreeData(circle,MFFreeCircleData,e);
  MFIMFSetProject(circle,MFProjectCircle,e);
  MFIMFSetTangent(circle,MFTangentCircle,e);
  MFIMFSetScale(circle,MFScaleCircle,e);
  MFIMFSetWriteData(circle,MFWriteCircleData,e);
  MFIMFSetProjectForSave(circle,MFCircleProjectToSave,e);
  MFIMFSetProjectForDraw(circle,MFCircleProjectToDraw,e);
  MFIMFSetProjectForBB(circle,MFCircleProjectForBB,e);

  MFIMFSetVectorFactory(circle,MFNVectorFactory,e);
  MFIMFSetMatrixFactory(circle,MFNKMatrixFactory,e);

  return circle;
 }
Beispiel #3
0
MFImplicitMF MFIMFCreateLOCA(LOCAData* data)
 {
  MFImplicitMF loca;
  MFNSpace space;

  loca=MFIMFCreateBaseClass(-1, data->np, "LOCA", data->mfErrorHandler);

  space=MFCreateLOCANSpace(data);
  MFIMFSetSpace(loca,space, data->mfErrorHandler);
  MFFreeNSpace(space, data->mfErrorHandler);

  MFIMFSetData(loca,(void*)data, data->mfErrorHandler);
  data->space=space;
  MFRefNSpace(space, data->mfErrorHandler);
  MFIMFSetFreeData(loca,MFLOCAFreeData, data->mfErrorHandler);
  MFIMFSetProject(loca,MFProjectLOCA, data->mfErrorHandler);
  MFIMFSetTangent(loca,MFTangentLOCA, data->mfErrorHandler);
  MFIMFSetScale(loca,MFScaleLOCA, data->mfErrorHandler);
  MFIMFSetProjectForSave(loca,MFLOCAProjectToDraw, data->mfErrorHandler);
  MFIMFSetProjectForDraw(loca,MFLOCAProjectToDraw, data->mfErrorHandler);
  MFIMFSetProjectForBB(loca,MFLOCAProjectToDraw, data->mfErrorHandler);

  return loca;
 }
/*! \fn MFImplicitMF MFIMFCreatePolygonIn3SpaceWithRadius(int nv,double *v,double R, MFErrorHandler e);
 *  \brief Creates a Euclidean plane which contains the given polygon (which is assumed to be flat).
 *
 *  \param nv The number of vertices.
 *  \param v  The vertices stored as (v[0+3*iv],v[1+3*iv],v[2+3*iv]).
 *  \param R  A radius to use for charts on the manifold.
 *  \param e  An error handler.
 *  \returns An implicitly defined manifold.
 */
MFImplicitMF MFIMFCreatePolygonIn3SpaceWithRadius(int n,double *v,double R, MFErrorHandler e)
 {
  static char RoutineName[]={"MFIMFCreatePolygonIn3SpaceWithRadius"};
  MFImplicitMF polygon;
  MFNSpace space;
  struct MFPolygonIn3SpaceData *p;
  double d;
  int verbose=0;
  int i;

#ifdef MFALLOWVERBOSE
  if(verbose)
   {
    printf("%s\n",RoutineName);
    printf("%d\n",n);
    for(i=0;i<n;i++)
     printf("   %d (%lf,%lf,%lf)\n",i,v[3*i],v[3*i+1],v[3*i+2]);
    fflush(stdout);
   }
#endif

  polygon=MFIMFCreateBaseClass(3,2,"PolygonIn3Space",e);

  space=MFCreateNSpace(3,e);
  MFIMFSetSpace(polygon,space,e);
  MFFreeNSpace(space,e);

  p=(struct MFPolygonIn3SpaceData*)malloc(sizeof(struct MFPolygonIn3SpaceData));

#ifndef MFNOSAFETYNET
  if(p==NULL)
   {
    sprintf(MFPolygonMFErrorHandlerMsg,"Out of memory, trying to allocate %d bytes",sizeof(struct MFPolygonIn3SpaceData));
    MFSetError(e,12,RoutineName,MFPolygonMFErrorHandlerMsg,__LINE__,__FILE__);
    MFErrorHandlerOutOfMemory(e);
    return NULL;
   }
#endif

  p->r=R;
  p->ox=v[0];
  p->oy=v[1];
  p->oz=v[2];

#ifdef MFALLOWVERBOSE
  if(verbose){printf("  o=(%lf,%lf,%lf)\n",p->ox,p->oy,p->oz);fflush(stdout);}
#endif

  p->ax=v[3]-v[0];
  p->ay=v[4]-v[1];
  p->az=v[5]-v[2];
  d=1./sqrt(p->ax*p->ax+p->ay*p->ay+p->az*p->az);
  p->ax=p->ax*d;
  p->ay=p->ay*d;
  p->az=p->az*d;

#ifdef MFALLOWVERBOSE
  if(verbose){printf("  a=(%lf,%lf,%lf)\n",p->ax,p->ay,p->az);fflush(stdout);}
#endif

  p->bx=v[6]-v[0];
  p->by=v[7]-v[1];
  p->bz=v[8]-v[2];
  d=p->ax*p->bx+p->ay*p->by+p->az*p->bz;
  p->bx-=p->ax*d;
  p->by-=p->ay*d;
  p->bz-=p->az*d;
  d=1./sqrt(p->bx*p->bx+p->by*p->by+p->bz*p->bz);
  p->bx=p->bx*d;
  p->by=p->by*d;
  p->bz=p->bz*d;

#ifdef MFALLOWVERBOSE
  if(verbose){printf("  b=(%lf,%lf,%lf)\n",p->bx,p->by,p->bz);fflush(stdout);}
#endif

  p->nx=p->ay*p->bz-p->az*p->by;
  p->ny=p->az*p->bx-p->ax*p->bz;
  p->nz=p->ax*p->by-p->ay*p->bx;

#ifdef MFALLOWVERBOSE
  if(verbose){printf("  n=(%lf,%lf,%lf)\n",p->nx,p->ny,p->nz);fflush(stdout);}
#endif

  MFIMFSetData(polygon,(void*)p,e);
  MFIMFSetFreeData(polygon,MFFreePolygonIn3SpaceData,e);
  MFIMFSetProject(polygon,MFProjectPolygonIn3Space,e);
  MFIMFSetTangent(polygon,MFTangentPolygonIn3Space,e);
  MFIMFSetScale(polygon,MFScalePolygonIn3Space,e);
  MFIMFSetR(polygon,R,e);
  MFIMFSetProjectForBB(polygon,MFPolygonIn3SpaceProjectForBB,e);
  MFIMFSetProjectForDraw(polygon,MFPolygonIn3SpaceProjectForBB,e);
  MFIMFSetWriteData(polygon,MFWritePolygonIn3SpaceData,e);

  MFIMFSetVectorFactory(polygon,MFNVectorFactory,e);
  MFIMFSetMatrixFactory(polygon,MFNKMatrixFactory,e);

/* Test */

#ifdef MFALLOWVERBOSE
  if(verbose)
   {
    printf("Tangent [ %lf %lf %lf ]\n",
             (p->ax*p->ax+p->ay*p->ay+p->az*p->az),
             (p->ax*p->bx+p->ay*p->by+p->az*p->bz),
             (p->ax*p->nx+p->ay*p->ny+p->az*p->nz));
    printf("        [ %lf %lf %lf ]\n",
             (p->bx*p->ax+p->by*p->ay+p->bz*p->az),
             (p->bx*p->bx+p->by*p->by+p->bz*p->bz),
             (p->bx*p->nx+p->by*p->ny+p->bz*p->nz));
    printf("        [ %lf %lf %lf ]\n",
             (p->nx*p->ax+p->ny*p->ay+p->nz*p->az),
             (p->nx*p->bx+p->ny*p->by+p->nz*p->bz),
             (p->nx*p->nx+p->ny*p->ny+p->nz*p->nz));
    for(i=1;i<n;i++)
     {
      d=(p->nx*(v[3*i]-v[0])+p->ny*(v[3*i+1]-v[1])+p->nz*(v[3*i+2]-v[2]));
      printf("  (x[%d]-x[0]).n=%lf\n",i,d);
     }
    printf("done %s\n",RoutineName);fflush(stdout);
   }
#endif

  return polygon;
 }
Beispiel #5
0
/*! \fn MFImplicitMF MFIMFCreateEdgeIn3SpaceWithRadius(double *o,double *d,double R, MFErrorHandler e);
 *  \brief Creates a Euclidean line which contains the segment between the points l and r (left and right).
 *
 *  \param o An array of length at least 3, with the coordinates of the left end point of the interval.
 *  \param d An array of length at least 3, with the coordinates of the right end point of the interval.
 *  \param R  A radius to use for charts on the manifold.
 *  \param e An error handler.
 *  \returns An implicitly defined manifold.
 */
MFImplicitMF MFIMFCreateEdgeIn3SpaceWithRadius(double *v0, double *v1,double R, MFErrorHandler e)
 {
  static char RoutineName[]={"MFIMFCreateEdgeIn3SpaceWithRadius"};
  MFImplicitMF edge;
  MFNSpace space;
  struct MFEdgeIn3SpaceData *p;
  double d;
  int verbose=0;
  int i;

#ifdef MFALLOWVERBOSE
  if(verbose)printf("%s\n",RoutineName);
#endif

  edge=MFIMFCreateBaseClass(3,1,"EdgeIn3Space",e);

  space=MFCreateNSpace(3,e);
  MFIMFSetSpace(edge,space,e);
  MFFreeNSpace(space,e);

  p=(struct MFEdgeIn3SpaceData*)malloc(sizeof(struct MFEdgeIn3SpaceData));

#ifndef MFNOSAFETYNET
  if(p==NULL)
   {
    sprintf(MFEdgeMFErrorHandlerMsg,"Out of memory, trying to allocate %d bytes",sizeof(struct MFEdgeIn3SpaceData));
    MFSetError(e,12,RoutineName,MFEdgeMFErrorHandlerMsg,__LINE__,__FILE__);
    MFErrorHandlerOutOfMemory(e);
    return NULL;
   }
#endif

  p->r=R;
  p->ox=v0[0];
  p->oy=v0[1];
  p->oz=v0[2];
  p->ax=v1[0]-v0[0];
  p->ay=v1[1]-v0[1];
  p->az=v1[2]-v0[2];
  d=1./sqrt(p->ax*p->ax+p->ay*p->ay+p->az*p->az);
  p->ax=p->ax*d;
  p->ay=p->ay*d;
  p->az=p->az*d;

#ifdef MFALLOWVERBOSE
  if(verbose){printf("%s, data=0x%8.8x, o=(%lf,%lf,%lf), n=(%lf,%lf,%lf)\n",RoutineName,p,p->ox,p->oy,p->oz,p->ax,p->ay,p->az);fflush(stdout);}
#endif

  MFIMFSetData(edge,(void*)p,e);
  MFIMFSetFreeData(edge,MFFreeEdgeIn3SpaceData,e);
  MFIMFSetProject(edge,MFProjectEdgeIn3Space,e);
  MFIMFSetProjectForBB(edge,MFEdgeIn3SpaceProjectForBB,e);
  MFIMFSetProjectForDraw(edge,MFEdgeIn3SpaceProjectForBB,e);
  MFIMFSetTangent(edge,MFTangentEdgeIn3Space,e);
  MFIMFSetScale(edge,MFScaleEdgeIn3Space,e);
  MFIMFSetR(edge,R,e);
  MFIMFSetWriteData(edge,MFWriteEdgeIn3SpaceData,e);

  MFIMFSetVectorFactory(edge,MFNVectorFactory,e);
  MFIMFSetMatrixFactory(edge,MFNKMatrixFactory,e);

#ifdef MFALLOWVERBOSE
  if(verbose){printf("done %s\n",RoutineName);fflush(stdout);}
#endif

  return edge;
 }