rapidform tutorial

115
Rapidform.dll Tutorial INUS Technology, Inc.

Upload: truong-ngo-tuan

Post on 27-Dec-2015

173 views

Category:

Documents


9 download

TRANSCRIPT

Page 1: Rapidform Tutorial

Rapidform.dll Tutorial

INUS Technology, Inc.

Page 2: Rapidform Tutorial

Contents

• Overview• Visual C++ environment setting• Basic definition• Entity interfaces• Primitives• Geometric calculation APIs• Command APIs• Display• Selection

Page 3: Rapidform Tutorial

OVERVIEW

Page 4: Rapidform Tutorial

Overview

• Architecture– Single model support– Internal unit: millimeters[mm], radian[radian]

Primitive object

Kernel DB

Command APIs

Kernel DB Interfaces

RFCmdFileIOAPI, RFCmdPolygonAPI, …

CINSPoint, CINSVector, CINSPlane, …

IRFModel, IRFFeature, IRFShell, …

Application

Rapidform.dll

Geometric Calculation APIs

INSCGAPI, CINSLSQFitAPI, …

Page 5: Rapidform Tutorial

• Entities of RAPIDFORM

Overview

Model

Curve

Surface

Shell

Vertex

Face

Curve

Surface

Page 6: Rapidform Tutorial

• Work Process

Overview

Point clouds or meshes

Pre-process

Align

Generate mesh

Post-process

Generate Curve

Generate Surface

Calculate deviation

Polygon

Page 7: Rapidform Tutorial

VISUAL C++ ENVIRONMENT SETTING

Page 8: Rapidform Tutorial

Visual C++ Environment Setting

• Built in Microsoft Visual C++ 2003(VC71) and 2005(VC80)• Specify Additional Include Directories

– Installed directory\Rapidform Library\Include

• Ex) C:\Program Files\INUS Technology\Rapidform.dll\Rapidform Library\Include

• Specify Additional Library Directories– Installed directory\Rapidform Library\Lib\VC71– Installed directory\Rapidform Library\Lib\VC80

• Ex) C:\Program Files\INUS Technology\Rapidform.dll\Rapidform Library\Lib\VC71• Ex) C:\Program Files\INUS Technology\Rapidform.dll\Rapidform Library\Lib\VC80

• Specify Additional Dependencies– Add RapiformDev.lib for evaluation version– Add Rapidform.lib for license free released version

• Copy installed DLLs to where your execute file exists– Installed directory\Rapidform Library\Dll\VC71– Installed directory\Rapidform Library\Dll\VC80

Page 9: Rapidform Tutorial

Visual C++ Environment Setting

• Specify Additional Include Directories

Page 10: Rapidform Tutorial

Visual C++ Environment Setting

• Specify Additional Library Directories

Page 11: Rapidform Tutorial

Visual C++ Environment Setting

• Specify Additional Dependencies

Page 12: Rapidform Tutorial

Visual C++ Environment Setting

• Specify Struct Member Alignment

Page 13: Rapidform Tutorial

Visual C++ Environment Setting

• Specify Character Set

Page 14: Rapidform Tutorial

Visual C++ Environment Setting

• Specify Runtime Library

Page 15: Rapidform Tutorial

Visual C++ Environment Setting

• Exercise– Build your APITest project

@ Installed directory\Example Application\APITest\APITest_VC71.sln

Page 16: Rapidform Tutorial

BASIC DEFINITION

Page 17: Rapidform Tutorial

Basic Definition

• INSStatus– Return value of low level API’s and kernel entity’s interface– typedef long INSStatus;

– INSERROR_OK• 0; No error occurs.

– INSERROR_WARN• 1; Warning error occurs. That is ignorable.

– INSERROR_SEVERE• 2; Severe error occurs. The function can't continue.

– INSERROR_FATAL• 3; Fatal error occurs. The application can't continue.

Page 18: Rapidform Tutorial

Basic Definition

• eRFErrorCode– Return value of command API– RF_SUCCESS is returned if there is no error.

RF_SUCCESS = 0, //!< No error occurs.RF_ERROR_UNKNOWN = 1, //!< Unknown error occurs.RF_ERROR_USERBREAK, //!< User break.RF_ERROR_OUT_OF_MEMORY, //!< Out of memory error occurs.RF_ERROR_INVALID_RFMODEL, //!< The model ID is invalid.RF_ERROR_INVALID_ENTITY_ID, //!< The entity ID is invalid....RF_ERROR_END

Page 19: Rapidform Tutorial

Basic Definition

• INSEntityID– The unique kernel entity ID class– Three low-level IDs and entity type.– Each kernel entity is identified by an entity ID.– Entity ID is not retained over file I/O operations.– Entity interfaces provide SetID() method to specify an individual entity.– Entity interfaces provide Assert() method to check the validation of ID

typedef unsigned long   INSID;

typedef enum{ENTITY_UNDEFINED = 0,   ENTITY_MODEL, ENTITY_SHELL,           ENTITY_FACE,            ENTITY_EDGEUSE,         ENTITY_VERTEX,          ENTITY_CURVE,           ENTITY_SURFACE,         

} INSEntityType;

class INSEntityID{

INSID m_ID1;  INSID m_ID2;  INSID m_ID3;  INSEntityType m_Type;

};

Page 20: Rapidform Tutorial

Basic Definition

• INSEntityID

Type (m_Type) Owner ID (m_ID1) Low ID (m_ID2) Aux ID (m_ID3)

ENTITY_MODEL Model ID Model ID

ENTITY_SHELL Model ID Shell ID

ENTITY_FACE Shell ID Face ID

ENTITY_VERTEX Shell ID Vertex ID

ENTITY_EDGEUSE Left Face ID Start Vertex ID End Vertex ID

ENTITY_CURVE Model ID Curve ID

ENTITY_SURFACE Model ID Surface ID

< EDGEUSE >

Start Vertex

End Vertex Start Vertex

End Vertex

Left Face

Left Face

Page 21: Rapidform Tutorial

ENTITY INTERFACES

Page 22: Rapidform Tutorial

Entity Interfaces

• IRFEntity– IRFModel– IRFShell– IRFFace– IRFVertex– IRFEdgeUse– IRFBSplineCurve– IRFBSplineSurface

Page 23: Rapidform Tutorial

IRFEntity

• Common interface of entity

• SetID()/GetID()– Set/Get interface’s entity ID

INSEntityID ShellID;IRFShell iSh;iSh.SetID(ShellID);ShellId = iSh.GetID();

• Assert()– Check whether entity exist or not

if (iSh.Assert() != true) {// shell does not exist !

}

Page 24: Rapidform Tutorial

IRFEntity

• Transform()– Transform entity with homogeneous transform matrix

CINSTMatrix matrix(30*(PI/180), 0, 0, 0, 0, 0);iSh.Transform(matrix); // rotate shell 30 degree around x‐axis.

• GetMinMaxBox()– Get axis-aligned bounding box of entity

CINSBox ShBox;iSh.GetMinMaxBox(ShBox);

x‐axisRotation

Page 25: Rapidform Tutorial

IRFModel

• Interface of the model• Single model support• Containing all kernel entities such as shells, curves and surfaces

Page 26: Rapidform Tutorial

IRFModel

• Add entity to the model– AddShell()

IRFModel iMd;INSEntityID shellID;iMd.AddShell(INS_GENERIC_SHELL, “shell name”, shellID);

• Delete entity of the model– DeleteShell(), DeleteShellAll(), DeleteBSplineCurve(), DeleteBSplineSurface()

iMd.DeleteShell(shellID);iMd.DeleteBSplineCurve(curveID);

• Get number of entities– GetNumOfShells(), GetNumOfBSplineCurves(), GetNumOfBSplineSurfaces()

int NumShells;iMd.GetNumOfShells(NumShells);

Shell Curve Surface

Page 27: Rapidform Tutorial

IRFModel

• Enumeration container– Includes entity IDs and current position in ID array

– int Size() - Get number of entities– void Reset() - reset current position– INSEntityID Next() - return ID at current position & increase current position

– CINSEnumEntities• Containing copied ID array of enumerated entities• Because of copying, enumeration can be slow when number of entities is

larger (i.e. vertices or faces of shell)

– CINSEnumEntitiesConst• Constant version of CINSEnumEntities• Containing owner entity’s array pointer directly, not copying it• Only available for vertices and faces• Modifying(adding or deleting) sub-entities of owner entity is not allowable.

Page 28: Rapidform Tutorial

IRFModel

• Enumerate sub-entities of the model– Enumeration container pointer should be deleted after use.– EnumShells(), EnumCurves(), EnumSurfaces()

IRFModel iMd;IRFShell iSh;CINSEnumEntities *pEnumShells=NULL;

if (iMd.EnumShells(pEnumShells) == INSERROR_OK){

for (int i=0; i< pEnumShells‐>Size(); i++){

iSh.SetID(pEnumShells‐>Next());// add codes…

}}

if (pEnumShells)RFDELETE_AND_NULL(pEnumShells);

Page 29: Rapidform Tutorial

IRFShell

• Interface of shell (point cloud or polygonal mesh)• Support only triangular mesh• Containing sub-entities such as vertices, faces and edges

Point cloud Polygonal mesh

Shell

Page 30: Rapidform Tutorial

IRFShell

• Shell type– INS_GENERIC_SHELL– INS_MEASURED_SHELL

• If the shell has a local coordinate (i.e. camera coordinate), shell should be added to the model with this type.

• When adding a vertex to the shell, the vertex’s coordinate should be global coordinate.

• This property is used in 2D triangulate.Z-direction is viewing direction of camera. (see 2D triangulation)

• SetMeasuringCoordinate(), GetMeasuringCoordinate()

CINSPoint Orgin;CINSUnitVector Uaxis, Vaxis;CINSCoordinate MeasureCoord;

iSh.SetMeasuringCoordinate(Origin.x, Origin.y, Origin.z,Uaxis.x, Uaxis.y, Uaxis.z, Vaxis.x, Vaxis.y, Vaxis.z);

iSh.GetMeasuringCoordinate(MeasureCoord);

Page 31: Rapidform Tutorial

IRFShell

• Add entity to the shell– AddFace(), AddVertex()

IRFShell iSh;INSEntityID VtID[3], FcID;iSh.AddVertex(0,0,0, VtID[0]); // vertex1(0,0,0)iSh.AddVertex(0,1,0, VtID[1]);  // vertex2(0,1,0)iSh.AddVertex(1,0,0, VtID[2]);  // vertex3(1,0,0)iSh.AddFace(VtID[0], VtID[1], VtID[2], true, FcID);

Page 32: Rapidform Tutorial

IRFShell

• Delete entity of the shell– DeleteFace(), DeleteFaceAll(), DeleteVertex(), DeleteVertexAll()– DeleteDanglingVertexAll()

• Delete all vertices which has no face– DeleteDanglingFaceAll(int nEdge= 3)

• Delete all faces which has more edges than nEdge

iSh.DeleteFace(FcID);iSh.DeleteVertex(VtID[0]);iSh.DeleteDanglingVertexAll();iSh.DeleteDanglingFaceAll(3);

Page 33: Rapidform Tutorial

IRFShell

• Enumerate sub-entities of the shell– Enumeration container pointer should be deleted after use.– EnumLoops(), EnumFaces(), EnumEdgeUses(), EnumVertecies()– EnumAllVerticesConst(), EnumAllFacesConst()

• Constant version

INSEntityID ShellID;IRFShell iSh(ShellID);CINSEnumEntitiesConst *pEnumFaces=NULL;IRFFace iFc;

if (iSh.EnumAllFacesConst(pEnumFaces) == INSERROR_OK){

for (int i=0; i < pEnumFaces‐>Size(); i++){

iFc.SetID(pEnumFaces‐>Next());// add codes…

}}

if (pEnumFaces)RFDELETE_AND_NULL(pEnumFaces);

Page 34: Rapidform Tutorial

IRFShell

• Get geometric property– CalcArea(), CalcVolume(), IsClosed()

double dArea, dVolume;iSh.CalcArea(dArea);iSh.CalcVolume(dVolume);

• Set/Get property– SetLock(), IsLock()

• Set/Get a lock status of the shell• In registration API, only unlocked shells are moving. (see align)

bool bLocked;iSh.IsLock(bLocked);iSh.SetLock(bLocked);

Page 35: Rapidform Tutorial

IRFShell

• Update geometries of the shell– Below methods should be called once after modifying shell

– CalcMinMaxBox()• Calculate axis-aligned box of shells

– Regenerate(bool bMinMaxBox=true, bool bRegenNormal=true)• Update the min-max box of shell and the normal of vertex.• Includes CalcMinMaxBox(), if bMinMaxBox is true

Page 36: Rapidform Tutorial

IRFShell

• CRFKDLumpTreeF– K-dimensional binary tree that represents hierarchically decomposed space by

half planes– It is used for searching min-distance vertex from point quickly.

– CreateKDLumpTreeF(CRFKDLumpTreeF *&prKDTree)

class CRFKDLumpTreeF;

typedef struct {INSID id; // vertex’s low IDfloat xyz[3];// vertex’s position

} KDTreeNodeF;

typedef struct queueNode2F {float dist; // Square distanceKDTreeNodeF *elem;// element to be foundstruct queueNode2F *next;

} KDLumpTreeQUEUEF;

※ Please note that farther point(vertex) comes first.

Page 37: Rapidform Tutorial

IRFShell

• CRFKDLumpTreeF

IRFShell iSh(ShellID);CRFKDLumpTreeF *pKDTree=NULL;

if (iSh.CreateKDLumpTreeF(pKDTree) == INSERROR_OK){

const int nDepth; // we will find three closest vertexKDLumpTreeQUEUEF *que, sque[nDepth+2]; // queue to store closest nodes, its size is depth + 2bool bIgnoreOuterPoint = false; // if it is true, searching is fast but not exact.float query[3] = { 0.0f, 0.0f, 0.0f}; // position to search closest vertices

if (pKDTree‐>Search(query, nDepth +1, sque, bIgnoreOuterPoint)) {for (que = sque [0].next‐>next; que!= NULL && que >elem != NULL; que = que >next){//que‐>dist: square distance, que‐>elem‐>id: vertex’s low id// vertex’s id is INSEntityID(iSh.GetLowID(), que‐>elem‐>id, 0, ENTITY_VERTEX).// add code…}

}}if (pKDTree)

RFDELETE_AND_NULL(pKDTree);

Page 38: Rapidform Tutorial

IRFShell

• CINSEncodedFaceSet – 3D grid structure to encode face geometries spatially.– It is used for searching ray intersection position or closest position on face.– Only available for mesh shells.

– CreateEncodedFaceSet(int Resolution/*=0*/, CINSEncodedFaceSet *&prEncSet)

X

Y

Z

Resolution = 4

Infinite ray

Page 39: Rapidform Tutorial

IRFShell

• CINSEncodedFaceSet

IRFShell iSh(ShellID);CINSEncodedFaceSet *pEncFcSet=NULL;

if (iSh.CreateEncodedFaceSet(0, pEncFcSet) == INSERROR_OK){

bool bFound;double SeedPt[3], SeedNorm[3], xPt[3], xS, xT, dSQDistance;INSID xFcID;

// Set SeedPt & SeedNormbFound = pEncFcSet‐>FindRayTriangleXPoint(SeedPt, SeedNorm, &xFcID, &xS, &xT, xPt, true, false);

bFound = pEncFcSet‐>FindClosestFace(SeedPt, &xFcID, xPt, &xS, &xT, &dSQDistance);

/* xS, xT is bicentric coordinatexPt = (1‐xS‐xT)*P1 + xS*P2 + xT*P3 = P1 + xS*(P2‐P1) + xT*(P3‐P1)(Here, P1,P2 and P3 are the points of Face) */

}

if (pEncFcSet)RFDELETE_AND_NULL(pEncFcSet);

Page 40: Rapidform Tutorial

IRFFace

• Interface of face• Support only triangular mesh• The normal direction is defined by CCW.

Face

Vertex 1

Vertex 2

Vertex 3

Adj. Faces

Adj. Faces of vertices 1,2 and 3

Face

Vertex 1

Vertex 2

Vertex 3

Adj. Faces

Non-manifold edge

• More faces than three have a common edge• Two faces have a common vertex and non

common edge • Neighbor faces have each opposite directions

Non-manifold edge

Page 41: Rapidform Tutorial

IRFFace

• Enumerate entities– GetShellID()– GetEdgeUses(INSEntityID *, INSEntityID *, INSEntityID *)– GetVertices(INSEntityID *, INSEntityID *, INSEntityID *)– EnumAdjacentFaces(CINSEnumEntities *&)– EnumAdjacentFacesOfVertices(CINSEnumEntities *&)

Face

Vertex 1

Vertex 2

Vertex 3

Adj. Faces

Adj. Faces of vertices 1,2 and 3

Page 42: Rapidform Tutorial

IRFFace

• Get geometric property– GetPoints(CINSPoint *, CINSPoint *, CINSPoint *)– CalcArea(), CalcMeanLengthOfEdges(), CalcCenter()– CalcNormal(CINSVector &rNormal, bool bAreaFactor = false);

• Methods for topological property– ReverseNormal()

• Reverse vertices’ order– IsDegenerate()

• Whether zero-length edge is or not

Page 43: Rapidform Tutorial

IRFVertex

• Interface of vertex• 3D spatial coordinates• UV texture mapping coordinates• Vertex color

VertexDepth=1

Adj. Faces

Depth=2Adj. Faces

Depth=1Adj. Vertices

Depth=2Adj. Vertices

Page 44: Rapidform Tutorial

IRFVertex

• Enumerate entities– GetShellID()– GetNumOfAdjacentFaces(), EnumAdjacentFaces()– EnumDepthAdjacentFaces(int, CINSEnumEntities *&)– EnumAdjacentEdgeUses(), EnumAdjacentReverseEdgeUses()– GetNumOfAdjacentVertices(), EnumAdjacentVertices()– EnumDepthAdjacentVertices(int, CINSEnumEntities *&)

VertexDepth=1

Adj. Faces

Depth=2Adj. Faces

Depth=1Adj. Vertices

Depth=2Adj. Vertices

Page 45: Rapidform Tutorial

IRFVertex

• Get geometric property– GetPoint(), SetPoint()– GetColor(), SetColor()– SetNormal(), GetNormal()– CalcNormal(CINSUnitVector &rNormal, bool bIsAreaNormal = false)

• Methods for topological property– IsBoundary()– HasRedundantFaces()

• If # of adj. vts. < # of adj. fcs., this has redundant faces.– IsDegenerate()

• If this vertex is one of the zero length edge, it is degenerated.

Page 46: Rapidform Tutorial

IRFEdgeUse

• Interface of edge use• Start & end vertex.• Temporary entity – this is not stored in the kernel DB.

Left face

Right faceRight vertex

Left vertex

Next EdgeUse

Previous EdgeUse

Start vertex

End vertex

Face

Vertex 1

Vertex 2

Vertex 3

Adj. Faces

Non-manifold edge

Page 47: Rapidform Tutorial

IRFEdgeUse

• Enumerate entities– GetShellID()– GetType(INSEdgeUseType &rType)

• INS_NORMAL_EDGEUSE: Edge having two faces• INS_BOUNDARY_EDGEUSE: Edge having one face

– GetNumOfAdjacentFaces(), EnumAdjacentFaces()– GetLeftFace(), GetRightFace()– GetPrevEdgeUse(), GetNextEdgeUse()– GetStartVertex(), GetEndVertex(), GetVertices()– GetLeftVertexID(), GetRightVertexID()– GetSymEdgeUse()

• Return reversed edge

Left face

Right faceRight vertex

Left vertex

Next EdgeUse

Previous EdgeUse

Start vertex

End vertex

Reversed edge

Page 48: Rapidform Tutorial

IRFEdgeUse

• Get geometric property– GetStartPoint(), GetEndPoint(), GetPoints()– CalcDirection()– CalcLength()– CalcAngle()

• Angle between left & right faces– CalcNormalAngle()

• Angle between left & right faces’ normal

• Method for topological property– IsBoundary(), IsManifold()

Page 49: Rapidform Tutorial

Entity Interfaces

• NURBS(Non-uniform Rational B-Spline)

– B-Spline Curve– B-Spline Surface

• Degree(=order-1)• Control point• Homogeneous coordinate• Knot vector

Page 50: Rapidform Tutorial

IRFBSplineCurve

• Interface of B-Spline Curve

• Get geometric property– EvaluatePoint(), EvaluateTangent(), EvaluateCurvature(), EvaluateTorsion()

• Evaluate value at given parameter– Reverse(), CalcLength()– ProjectPoint()

• Project point to B-Spline curve– GetControlPoints(), SetControlPoints()

Page 51: Rapidform Tutorial

IRFBSplineCurve

• Tessellate curve– GenerateInterpolationPoints(CArray<CINSPoint, CINSPoint&>&, double

dChordHeightTol)• Get tessellated points• This can be used for displaying a curve.

INSEntityID curveID;IRFBSplineCurve iCurve(curveID);double dChordHeightTol = 0.01;CArray<CINSPoint, CINSPoint&> ArrTessPoints;iCurve.GenerateInterpolationPoints(ArrTessPoints, dChordHeightTol);

Page 52: Rapidform Tutorial

IRFBSplineSurface

• Interface of B-Spline Surface

• Get geometric property– EvaluateTangent(), EvaluateCurvature(), EvaluateNormal(), EvaluatePoint()

Evaluate value at given parameter– Reverse()– ProjectPoint(), NormalizePoint()

• Project point to B-Spline curve by shortest or normalized (orthogonal to surface) method

– GetControlPoints(), SetControlPoints()

Page 53: Rapidform Tutorial

IRFBSplineSurface

• Tessellate surface– CalcAutoTessResolution(SRFSurfTessParam &, eRFSurfTessResolution)

• Get tessellation option automatically– Tessellate(SRFSurfTessMesh&, SRFSurfTessParam)

• Tessellate surface with given option

typedef enum{INS_SURFTESS_LOWEST = 0,INS_SURFTESS_LOW,INS_SURFTESS_MEDIUM,INS_SURFTESS_HIGH,INS_SURFTESS_HIGHEST,} eRFSurfTessResolution;

Struct SRFSurfTessParam{ULONG lMinCurveDivisions;double dChordHeightTol;double dAngleTolInDegrees;double dMax3DEdgeLength;double dMin3DEdgeLength;double dMaxAspectRatio;double dMinUVRatio;bool bIncBoundaries;};

struct SRFSurfTessMesh{int iNumMeshVts;int iNumMeshFcs;float *pfMeshVtsData; // iNumMeshVts x 3float *pfMeshNormData; // iNumMeshVts x 3int *piMeshFcsData; // iNumMeshFcs x 3

// for boundariesCArray<CArray<CINSPoint, CINSPoint&>*, CArray<CINSPoint, CINSPoint&>*&> *pArrBoundariesData;};

Page 54: Rapidform Tutorial

IRFBSplineSurface

• Tessellate surface

INSEntityID surfaceID;IRFBSplineSurface iSurf(surfaceID);

SRFSurfTessParam TessParam;SRFSurfTessMesh TessMesh;

IRFBSplineSurface::CalcAutoTessResolution(TessParam, INS_SURFTESS_LOW);iSurf.Tessellate(TessMesh, TessParam);

Page 55: Rapidform Tutorial

PRIMITIVES

Page 56: Rapidform Tutorial

Primitives

• Primitives– Represent 2D/3D geometries– Rapidform Library/Include/INSPrimitives/

Data type Description Data type Description

CINSPoint 3D Euclidean point CINSPoint2D 2D Euclidean point

CINSVector 3D direction vector CINSVector2D 2D direction vector

CINSUnitVector 3D direction unit vector CINSUnitVector2D 2D direction unit vector

CINSLine 3D finite line geometry CINSLine2D 2D finite line geometry

CINSPlane Infinite plane geometry CINSCoordinate 3D coordinate system

CINSCircle 3D circle geometry CINSCircleArc 3D circular arc geometry

CINSSphere 3D sphere geometry CINSCylinder 3D finite cylinder geometry

CINSCone 3D finite cone geometry CINSBox 3D axis-aligned box geometry

CINSGeneralBox 3D box geometry CINSTorus 3D torus geometry

CINSTMatrix Homogeneous transform matrix

Page 57: Rapidform Tutorial

GEOMETRIC CALCULATION APIS

Page 58: Rapidform Tutorial

Geometric Calculation APIs

• class INSCGAPI– Rapidform Library/Include/INSCGAPI/INSCGApi.h

– Distance methods• PointPointDistance(), PointLineDistance(), PointPlaneDistance(), etc…

– Comparison methods• IsParallelVector(), IsPointOnLine(), IsPointInTriangle(), etc…

– Intersection methods• LineLineXPoint(), LinePlaneXPoint(), PlanePlaneXLine(), etc…

– Projection methods• PointProjectionOnLine(), PointProjectionOnPlane(), etc…

Page 59: Rapidform Tutorial

Geometric Calculation APIs

• class CINSEigenSystem– Rapidform Library/Include/INSCGAPI/GeomEigenSystem.h– Get eigen values & vectors

• SolveEigenSystemDecrSort3(), SolveEigenSystemDecrSort4(), etc…• This method can be used for get principal axes

• class CINSLSQFitAPI– Rapidform Library/Include/INSCGAPI/GeomLSQFit.h– Get least-square fitted geometries

• LSQFitXXX() ;XXX=Geometry, ex. LSQFitCylinder()– Calculate error statistics

• Min./Max./Avg./Var./Std.Dev. error• StatisticsOfXXX() ;XXX=Geometry, ex. StatisticsOfCylinder()

Page 60: Rapidform Tutorial

COMMAND APIS

Page 61: Rapidform Tutorial

Command APIs – File IO

• namespace RFCmdFileIOAPI– File I/O commands

• New model– New()

• Initialize the model• See OnNewDocument() @ APITestDoc.cpp

• Import/Export entities– ImportFile(), ExportFile()

• Import/Export the given entities from/to the given format file.• See OnFileImport(), OnFileExport() @ APITestDoc.cpp

– ImportMDL(), ExportMDL()• Import/Export the all entities of the model from/to MDL file format

Page 62: Rapidform Tutorial

Command APIs – File IO

• Import Format

– RapidForm Model File (*.mdl)– RapidForm Points File (*.pts)– RapidForm Polygons File (*.fcs)– Ascii Points File (*.asc)– 3D Studio File (*.3ds)– AutoCAD DXF File (*.dxf)– CyberWare File (*.ply)– Inventor 1.0 ASCII File (*.iv)– STL File (*.stl)– VRML 1.0/97 File (*.wrl)– OBJ File (*.obj)– Hymarc File (*.hym)– Vivid File (*.vvd, *.cdk, *.cdm, *.cam)– Steinbichler File (*.ac)– GOM File (*.view, *.cloud, *.g3d)– Kreon File (*.cbk, *.grk, *.cwk)– 3D Digital Corp. File (*.pmj, *.pmjx)– IGES File (*.iges, *.igs)– INUS Compression File (*.icf)– Breuckmann File (*.bre)– EOIS File (*.xyz, *.txt)– 3D Scanners File (*.sab, *.sab2)– 3DS MAX Ascii Export File (*.ase)– NEC Range Finder File (*.nrf, *.ntf)

– STEP File (*.step, *.stp)– VDAFS File (*.vda)– Cyra File (*.pts, *.ptx)– Scantech File (*.stb)– Surf File (*.surf)– PICZA File (*.pix)– Opton File (*.xyz, *.crs, *.lin, *.smh, *.bin)– Perceptron File (*.swl, *.swb, *.bin)– DeltaSphere File (*.rtpi, *.xyzi, *.xyzrgb)– ShapeGrabber File (*.3pi)– Mensi File (*.soi)– Solutionix File (*.icv, *.snx)– Wicks and Wilson File (*.tfm)– iQvolution File (*.iqscan)– Riegl File (*.3dd)– Optimet File (*.opd)

• Export Format

– RapidForm Model File (*.mdl)– RapidForm Points File (*.pts)– RapidForm Polygons File (*.fcs)– Ascii Points File (*.asc)– STL File (*.stl)– 3DS File (*.3ds)– OBJ File (*.obj)– IGES File (*.igs)

Page 63: Rapidform Tutorial

Command APIs – Polygon

• namespace RFCmdPolygonAPI– Point cloud & polygonal mesh commands

• Pre-process– Filtering, Sampling

• Align– Align initially, globally

• Generate mesh– 2D/3D triangulate, SCM– Merging, combining

• Post-process– Filling holes– Re-meshing– Decimating

Point clouds or meshes

Pre-process

Align

Generate mesh

Post-process

Work Process

Page 64: Rapidform Tutorial

Command APIs – Pre-process

• Delete noisy vertices

– FilterNoise(const INSEntityID &rcShID, double dMinClusterDist, unsigned int iMaxClusterSize)

• double dMinClusterDist– minimum distance between clusters.

• unsigned int iMaxClusterSize – Delete clusters which have less vertices than this parameter.

• See OnFilternoise() @ APITestDocMenu.cpp

Page 65: Rapidform Tutorial

Command APIs – Pre-process

• Delete noisy vertices

– Exercise• Import FilterNoise.mdl• Run “Mesh > Filter > Noise” menu.

Page 66: Rapidform Tutorial

Command APIs – Pre-process

• Delete redundant vertices

– FilterRedundancy (const INSEntityID &rcShID, double dRadius)

• double dRadius– distance criteria to determine whether vertices are redundant– If this parameter is 0.0, it will be calculated automatically.

• See OnFilterredundancy() @ APITestDocMenu.cpp

Page 67: Rapidform Tutorial

Command APIs – Pre-process

• Delete redundant vertices

– Exercise• Import filter_redundancy.mdl• Run “Mesh > Filter > Redundancy” menu.

Page 68: Rapidform Tutorial

Command APIs – Pre-process

• Delete vertices for shell to have uniform density

– UniformSampling (const INSEntityID &rcShID, double dSampleRatio, RFSamplingType eSamplingType)

• double dSampleRatio– the reduced vertex number to the original vertex number

• RFSamplingType eSamplingType– RF_SAMPLE_GENERAL = Sampling of point set in order of point input– RF_SAMPLE_LINE_GRID = Sampling of point set by voxel after

dividing point set into voxel• See OnUniformsampling() @ APITestDocMenu.cpp

Page 69: Rapidform Tutorial

Command APIs – Pre-process

• Delete vertices for shell to have uniform density

– Exercise• Import sampling.mdl• Run “Mesh > Filter > Uniform Sampling” menu.

Page 70: Rapidform Tutorial

Command APIs - Align

• Align two shell initially

– RegisterShellsQuick (const INSEntityID &rcRefShID, const INSEntityID &rcMovShID, CINSTMatrix &rMovTMat)

• Calculate the moving shell to the reference shell by using their principal coordinate

• CINSTMatrix rMovTMat– Result homogenous transform matrix

• See OnRegistershellsquick() @ APITestDocMenu.cpp

Page 71: Rapidform Tutorial

Command APIs - Align

• Align shells globally

– RegisterShells (const Carray<INSEntityID, INSEntityID&> &rcArrShIDs, Carray<CINSTMatrix, CINSTMatrix&> &rArrTransforms, double dLengthCriteriaMultiplier, const SRFRegisterParam &rcParam)

• Align moving shells to reference shells globally• locked status of shell (see shell interface) decide moving property.• Carray<CINSTMatrix, CINSTMatrix&> &rArrTransforms

– Homogeneous transform matrix of each shells– The size of array will be same as input shells

• double dLengthCriteriaMultiplier– Internal use

• const SRFRegisterParam &rcParam• See OnRegistershells() @ APITestDocMenu.cpp

Page 72: Rapidform Tutorial

Command APIs - Align

• Align shells globally

– RegisterShells option• struct SRFRegisterParam

– Bool m_bUseCustomMaxIteration– Int m_iCustomMaxIteration– Bool m_bUseCustomAveDeviation– double m_dCustomAveDeviation– bool m_bRemoveOutlier– bool m_bLockTransX– bool m_bLockTransY– bool m_bLockTransZ– bool m_bLockRotX– bool m_bLockRotY– bool m_bLockRotZ

Page 73: Rapidform Tutorial

Command APIs – Align

• Delete vertices for shell to have uniform density

– Exercise• Import align.mdl• Run “Mesh > Register> Quick” menu.• Run “Mesh > Register> Global” menu.

After quick register After global register

Page 74: Rapidform Tutorial

Command APIs – Generate mesh

• 2D Triangulate

– Triangulate2D (const INSEntityID &rcShID, const SRFTriangulate2DParam &rcParam)

• Apply Delaunay triangulation process with projected vertices on plane.• Z-direction is global Z-axis, but in measured shell z-direction is camera

direction. (see measured shell)

struct RFAPI SRFTriangulate2DParam{unsigned int m_uiVersion;RFTriangulateDirection m_eDirectionOption;CINSTMatrix m_CustomTransform;bool m_bConstraintLength;double m_dConstraintLength;bool m_bConstraintArea;double m_dConstraintArea;bool m_bConstraintRatio;double m_dConstraintRatio;bool m_bConstraintAngle;double m_dConstraintAngle;};

enum RFTriangulateDirection{RF_TRIANGULATE_DIRECTION_PLUS_Z = 1,RF_TRIANGULATE_DIRECTION_MINUS_Z,RF_TRIANGULATE_DIRECTION_CUSTOM};

Page 75: Rapidform Tutorial

Command APIs – Generate mesh

• 2D Triangulate

– Exercise• Import venus_point.mdl• Run “Mesh > Triangulate > 2D” menu.

Page 76: Rapidform Tutorial

Command APIs – Generate mesh

• 3D Triangulate

– EstimateTriangulate3DRadii (const INSEntityID &rcShID, CArray< double, double & > &ArrRadii)

– Triangulate3D (const INSEntityID &rcShID, const CArray< double, double & > &ArrRadii, bool bScanLineType)

Page 77: Rapidform Tutorial

Command APIs – Generate mesh

• 3D Triangulate

– Exercise• Import car.mdl• Run “Mesh > Triangulate > 3D” menu.

Page 78: Rapidform Tutorial

Command APIs – Generate mesh

• Generate mesh

– SphericalCoverMesh (const INSEntityID &ShID, const SRFSCMParam &rcParam)

• Struct SRFSCMParam– eSCMQuadricError m_eQError

» Accuracy of result mesh» (sparse) SCM_Q_ERROR_1 < … < SCM_Q_ERROR_7 (dense)

– bool m_bUseNormal– bool m_bSmooth– bool m_bPreserveBoundary– bool m_bOptimize

Page 79: Rapidform Tutorial

Command APIs – Generate mesh

• Combine shells

– CombineShells (const CArray< INSEntityID, INSEntityID & > &rcArrShIDs, INSEntityID &rResultShID, const SRFTextureParam &rcTextureParam)

• Combining method just adds vertices of other shells to one shell without any topological change

• INSEntityID rResultShID– Created combined shell ID

• struct SRFTextureParam– unsigned int m_uiVersion– bool m_bPreserveTexture– int m_iTextureResolution

» The resolution of newly created texture will be this parameter.

Page 80: Rapidform Tutorial

Command APIs – Generate mesh

• Combine shells

– Exercise• Import point_merge.mdl• Run “Mesh > Combine Shells” menu.

Page 81: Rapidform Tutorial

Command APIs – Generate mesh

• Merge point clouds

– MergeVertexShells(const CArray<INSEntityID, INSEntityID&> &rcArrShIDs, RFMergePointCloudShellOption eMergeOption, INSEntityID &rResultShID)

• Merging method combines input shells and reduces redundant vertices in overlap region (topological change).

• RFMergePointCloudShellOption eMergeOption– RF_MERGE_POINT_CLOUD_SHELL_MERGE

» Input shells will be deleted– RF_MERGE_POINT_CLOUD_SHELL_COPY_AND_MERGE

Page 82: Rapidform Tutorial

Command APIs – Generate mesh

• Merge point clouds

– Exercise• Import point_merge.mdl• Run “Mesh > Merge Shells > Point Cloud” menu.

Page 83: Rapidform Tutorial

Command APIs – Generate mesh

• Merge meshes

– MergeShells (const CArray< INSEntityID, INSEntityID & > &rcArrShIDs, double dCritTolRatio, INSEntityID &rResultShID, const SRFTextureParam &rcTextureParam)

• double dCritTolRatio– When faces are closer than dCritTolRatio * average length of face,

they will be merged.

Page 84: Rapidform Tutorial

Command APIs – Generate mesh

• Merge meshes

– Exercise• Import venus_register_fine.mdl• Run “Mesh > Merge Shells > Mesh” menu.

Page 85: Rapidform Tutorial

Command APIs – Generate mesh

• Merge shells by volume method

– VolumeMergeShells (const CArray< INSEntityID, INSEntityID & > &rcArrShIDs, double dResolution, bool bUseAvgNormalProjection, bool bOptimizeMesh, INSEntityID &rNewShID, const SRFTextureParam &rcTextureParam)

• double dResolution– Voxel resolution(= Ratio to average edge length), (0.0, 1.0]

• bool bUseAvgNormalProjection– Whether to average vertex normal vectors within a voxel or not

Page 86: Rapidform Tutorial

Command APIs – Generate mesh

• Merge shells by volume method

– Exercise• Import volume_merge1.mdl, volume_merge2.mdl• Run “Mesh > Merge Shells > Volume” menu.

Page 87: Rapidform Tutorial

Command APIs – Post-process

• Fill holes of shell

– FillHolesShell (const INSEntityID &rcShID, const SRFFillHoleParam &rcParam)

• struct SRFFillHoleParam– unsigned int m_uiVersion– unsigned long m_ulNumMaxVts

» Only loops whose vertices number is smaller than this parameter will be filled

– RFFillHoleMethod m_eMethod» RF_FILL_HOLE_PLANE» RF_FILL_HOLE_SMOOTH» RF_FILL_HOLE_CURVATURE

– bool m_bSmoothBoundary– bool m_bExceptLargestHole

Page 88: Rapidform Tutorial

Command APIs – Post-process

• Fill holes of shell

– Exercise• Import helmet.mdl• Run “Mesh > Fill holes > Shell” menu.

Page 89: Rapidform Tutorial

Command APIs – Post-process

• Fill holes of shell by volume method

– VolumeFillHolesShell (const INSEntityID &rcShID, const SRFVolumeFillHoleParam &rcParam)

• struct SRFVolumeFillHoleParam– unsigned int m_uiVersion;– double m_dResolution

» Voxel resolution(= Ratio to average edge length), (0.0, 1.0]– unsigned int m_iIteration– bool m_bExceptLargestHole– bool m_bOptimizeMesh

Page 90: Rapidform Tutorial

Command APIs – Post-process

• Fill holes of shell by volume method

– Exercise• Import volume_fillhole1.mdl• Run “Mesh > Fill Holes > Volume Shell” menu.

Page 91: Rapidform Tutorial

Command APIs – Post-process

• Reduce the number of face of shell

– DecimateShell (const INSEntityID &rcShID, double dReductionRatio, double dAllowableDeviation, const SRFDecimateParam &rcParam)

• Two operation modes– Reduction ratio

» specifies the percentage of the faces to be retained.– Allowable deviation

» specifies the allowable amount of the vertex displacement during decimation.

» If this value is positive, API will works this mode.

Page 92: Rapidform Tutorial

Command APIs – Post-process

• Reduce the number of face of shell– DecimateShell options

• double dReductionRatio– Ratio of decimation; (0, 1)

• double dAllowableDeviation– Demanding error bound

• struct SRFDecimateParam– Bool m_bPreserveVertices– Bool m_bPreserveBoundary– Bool m_bPreserveQuality– Bool m_bPreserveMark– Int m_iCurvatureBalance

» [preserve high curvatures] 1 < … < 6 [Regular mesh]– Bool m_bPreserveColor– int m_iColorBalance

» Demanding color balance; [1, 3]» Higher color balance, preserve color more than geometry

– Bool m_bPreserveTexture– Int m_iTextureResolution

Page 93: Rapidform Tutorial

Command APIs – Post-process

• Reduce the number of face of shell

– Exercise• Import helmet_decimated.mdl• Run “Mesh > Decimate > Shell” menu.

Page 94: Rapidform Tutorial

Command APIs – Post-process

• Re-triangulate shell to improve quality

– GlobalRemesh (const INSEntityID &ShID, const SRFGlobalRemeshParam &rcParam)

• struct SRFGlobalRemeshParam– double m_dVoxelEdgeLength– bool m_bPreserveTexture– int m_iTextureResolution

Page 95: Rapidform Tutorial

Command APIs – Post-process

• Re-triangulate shell to improve quality

– Exercise• Import helmet_decimated.mdl• Run “Mesh > Remesh > Shell” menu.

Page 96: Rapidform Tutorial

Command APIs – Post-process

• Re-triangulate shell to improve quality by volume method– GlobalVolumeHealing (

const INSEntityID &ShID, const SRFGlobalVolumeHealingParam &rcParam)

• struct SRFGlobalVolumeHealingParam– bool m_bResolutiontype– double m_dResolution

» If m_bResolution is true, m_dResolution is the ratio to average edge length. (0.0, 1.0]

» If m_bResolution is false, m_dResolution is the size of voxel– bool m_bOptimizeMesh– bool m_bSmooth– bool m_bDeleteSmallCluster– bool m_bMultipleRangeDataMode

» If m_bMultipleRangeDataMode is true, overlap regions are merged smoothly.

– bool m_bPreserveColorInfor– bool m_bPreserveBoundary– bool m_bPreserveTexture– intm_iTextureResolution

Page 97: Rapidform Tutorial

Command APIs – Polygon Wizard

• Mesh Generation Wizard (recommended process)

– Batch process of the mesh generation process– See OnMeshgenerationwizard() @ APITestDocMenu_MeshWizard.cpp– “Mesh > Mesh Generation Wizard” menu

Registration

Combine (+ make point-cloud shells)

SCM (+ backup result shell)

Remeshing

Subdividing

Refitting to backup shell(+ remove backup shell)

Enhancing

Decimating

Page 98: Rapidform Tutorial

Command APIs - Curve

• namespace RFCmdCurveAPI– Curves commands

• Create section curve– CreateSliceCurve(

const INSEntityID &rcShellID,const CINSPlane &rcPlane,unsigned long ulMaxCurveCount, CArray<INSEntityID, INSEntityID&> &rArrResultCvIDs)

• Create section curve of point cloud or polygonal shell• The maximum number of section curves to be created is ulMaxCurveCount.• See OnCreateslicecurve() @ APITestDocMenu.cpp

Page 99: Rapidform Tutorial

Command APIs - Curve

• Create section curve– Exercise

• Import shoe_last.mdl• Run “Curve > Slice” menu.

Page 100: Rapidform Tutorial

Command APIs - Surface

• namespace RFCmdSurfaceAPI

– CreatSurfaceByAutomatic(const SRFAutoSurfacingOption &rcOption, CArray<INSEntityID, INSEntityID&> &rArrResultSfIDs)

• See OnCreatsurfacebyautomatic() @ APITestDocMenu_AutoSurfacing.cpp

struct SRFAutoSurfacingOption {unsigned int m_uiVersion;INSEntityID m_OrgShID;INSEntityID m_RefShID;CArray<INSEntityID, INSEntityID&> *m_pArrFeatureCurves; bool m_bIgnoreUnmatchedPatchError; int m_iNumSurfaces; int m_iNumCtrlPts;int m_iFitAccuracy; // ranges from 0 to 9int m_iCaptureAccuracy; // ranges from 0 to 2bool m_bInitialRelax;bool m_bGlobalMatch;bool m_bRemoveSharpPatch;

}

Page 101: Rapidform Tutorial

Command APIs - Surface

• namespace RFCmdSurfaceAPI

• About 1000 patches of surface, double the number of polygon mesh, will be created

Auto surfacing

Original shell Reference shell Auto surfacing

Page 102: Rapidform Tutorial

Command APIs - Surface

• Exercise– Import duct_auto.mdl– Run “Surface > Automatic” menu

Page 103: Rapidform Tutorial

Command APIs - Inspect

• namespace RFCmdInspectAPI

– CalcModelDev(const CLumpArray<INSEntityID, INSEntityID&> &rcArrRefSh, const CLumpArray<INSEntityID, INSEntityID&> &rcArrDevSh, CLumpArray<CRFMDShVtMapF *, CRFMDShVtMapF *&> &rArrModelDev, double dMaxSearchDev, bool bUseNormal=true)

Page 104: Rapidform Tutorial

Command APIs - Inspect

• namespace RFCmdInspectAPI

– CalcModelDev results• CINSMap<INSID, INSID, CRFMDVtF, CRFMDVtF&>

– INSID = vertex low ID– CRFMDVtF = deviation value

• Class CRFMDVtF– unsigned long m_iNumDev– float m_dDev = dummy– float m_dMaxDev = max signed deviation– float m_dSumDev = sum signed deviation– float m_dMinDev = min signed deviation– float m_duMaxDev = max unsigned deviation– float m_duSumDev = sum unsigned deviation– float m_duMinDev = min unsigned deviation

Page 105: Rapidform Tutorial

Command APIs - Inspect

• namespace RFCmdInspectAPI

– CalcWholeDeviation(const INSEntityID &rcScanShID, const CLumpArray<INSEntityID, INSEntityID&> &rcArrDesignIDs, const SRFWholeDevParam &rcOption, CINSMap<INSID, INSID&, CRFWholeDevResult, CRFWholeDevResult&>

&rWholeDevMap)

Page 106: Rapidform Tutorial

Command APIs - Inspect

• namespace RFCmdInspectAPI

– CalcWholeDeviation option• struct SRFWholeDevParam

– double m_dMaxEdgeLength = Surface Tessellation option– double m_dMaxChordLength = Surface Tessellation option– INS_PROJECTION_METHOD m_ePrjMethod

» PROJECTION_NORMALIZE_METHOD» PROJECTION_MINDIST_METHOD» PROJECTION_X_DIRECT_METHOD» PROJECTION_Y_DIRECT_METHOD» PROJECTION_Z_DIRECT_METHOD

– INS_UNPROJECTION_METHOD m_eUnPrjMethod» UNPROJECTION_LEAVE_METHOD» UNPROJECTION_PLANE_METHOD» UNPROJECTION_EDGE_METHOD

– double m_dMaxSearchDev

Page 107: Rapidform Tutorial

X-axis

Command APIs - Inspect

PROJECTION_MINDIST_METHOD: minimum distance

PROJECTION_NORMALIZE_METHOD: 180 degree between a project direction and a surface normal

PROJECTION_X_DIRECT_METHOD: YZ Plane projection

PROJECTION_Z_DIRECT_METHOD: XY Plane projection

PROJECTION_Y_DIRECT_METHOD: XZ Plane projection

Y-axis

Z-axis

Page 108: Rapidform Tutorial

Command APIs - Inspect

• namespace RFCmdInspectAPI

– CalcWholeDeviation results• CINSMap<INSID, INSID&, CRFWholeDevResult, CRFWholeDevResult&>

– INSID = vertex low ID– CRFWholeDevResult = deviation value

• class CRFWholeDevResult– CINSPoint m_PrjPt– Double m_PrjDist– INSID m_PrjID

Page 109: Rapidform Tutorial

DISPLAY

Page 110: Rapidform Tutorial

Display

• See DrawShell() @ APITestView.cpp– Enumerate all faces or vertices– Draw face or vertex

• See DrawCurve() @ APITestView.cpp– Calculate tessellated curve points– Draw points

• See DrawSurface() @ APITestView.cpp– Calculate tessellated surface mesh– Draw mesh

• openGL display list can be used.– User should update display list when entity is modified.

Page 111: Rapidform Tutorial

SELECTION

Page 112: Rapidform Tutorial

Selection

• See class CAPITestPick @ APITestPick.h/cpp– Load Name which is low ID of entity

• Use glLoadName()– Draw entity

Page 113: Rapidform Tutorial

ETC.

Page 114: Rapidform Tutorial

Etc.

• Include directories– INSTemplate includes basic template and macro functions and C++ containers.– INSBase includes basic definitions and calculation tolerance manager.– INSMatrix include matrix classes.– INSPrimitives include primitive geometry classes.– INSCGAPI includes mathematical APIs.– INSGDB include definitions of entity, IDs and other C++ containers.– INSSystemAPI include definitions for visualization materials.– INSRapidForm include interfaces of all entity types and command APIs.

• Help document– Installed directory\Documents\Rapidform.dll.chm

• Example application– Installed directory\Example Application\APITest\

Page 115: Rapidform Tutorial

Thank you

• Q & A