/*
* levels.c : To create the isoline-level of a 3D curve model.
*/
#include "levels.h"
long levels(long nump, POINT3D *node,
long numf, QFACE *face, long *layer,
long *numcp, POINT3D *cpoint,
long *numcurve, long *curvepos, long *curvelayer,
long axesFlag)
{
long pointMinZ, pointMaxZ;
double minZ, maxZ;
double scaleZ;
double levelBorder[NUMLEVELS];
long i;
double temp;
if ( axesFlag == 1 ) /* along X axes. */
{
for ( i=0; i<nump; i++)
{
temp = node[i].x;
node[i].x = node[i].z;
node[i].z = temp;
}
}
else if( axesFlag == 2 ) /* along Y axes. */
{
for ( i=0; i<nump; i++)
{
temp = node[i].y;
node[i].y = node[i].z;
node[i].z = temp;
}
}
else if( axesFlag == 3 ) /* along Z axes. */
{
;
}
else
{
printf("error: axesFlag is not between 1,2,3.\n");
exit(-3);
}
getScaleZ(nump, node, &pointMinZ, &pointMaxZ, &minZ, &maxZ, &scaleZ );
makeLevelBorder(&scaleZ, &minZ, &maxZ, levelBorder);
makeFaceSectionLine(nump, node, numf, face, layer, levelBorder);
makeCurves(numcp, cpoint, numcurve, curvepos, curvelayer);
if ( axesFlag == 1 ) /* along X axes. */
{
for ( i=0; i<nump; i++)
{
temp = node[i].z;
node[i].z = node[i].x;
node[i].x = temp;
}
for ( i=0; i<*numcp; i++)
{
temp = cpoint[i].z;
cpoint[i].z = cpoint[i].x;
cpoint[i].x = temp;
}
}
else if( axesFlag == 2 ) /* along Y axes. */
{
for ( i=0; i<nump; i++)
{
temp = node[i].z;
node[i].z = node[i].y;
node[i].y = temp;
}
for ( i=0; i<*numcp; i++)
{
temp = cpoint[i].z;
cpoint[i].z = cpoint[i].y;
cpoint[i].y = temp;
}
}
else if( axesFlag == 3 ) /* along Z axes. */
{
;
}
else
{
printf("error: axesFlag is not between 1,2,3.\n");
exit(-3);
}
return 0;
} //End of levels().
long makeCurves(long *numcp, POINT3D *cpoint,
long *numcurve, long *curvepos, long *curvelayer)
{
long i, j;
long numLevelCurves, numLevelPoints;
*numcp=0L;
*numcurve=0L;
for (i=0;i<NUMLEVELS;i++)
{
makeLevelCurves(i, &numLevelCurves, &numLevelPoints);
printf("level no. = %6ld, total curves = %6ld, "
"total points = %6ld.\n", i, numLevelCurves, numLevelPoints);
for (j=0;j<numLevelPoints;j++)
cpoint[*numcp+j] = levelCurves[j];
for (j=0;j<numLevelCurves;j++)
{
curvepos[*numcurve+j] = levelCurvePos[j] + *numcp;
curvelayer[*numcurve+j] = levelLayerIndex[j] ;
}
*numcp += numLevelPoints;
*numcurve += numLevelCurves;
}
return 0;
}//End of makeCurves().
long makeLevelCurves(long currentLevel, long *numLevelCurves, long *numLevelPoints)
{
long j;
long pHead, pEnd, currentLayer;
long numLeftLine;
long isNewCurve, isEndCurve;
long headLine, currentLine, currentCurvePos;
// long numLevelCurves, numLevelPoints;
isNewCurve = FALSE;
headLine = 0; currentLine = 0;
*numLevelCurves = 0; *numLevelPoints = 0;
numLeftLine = levelIndex[currentLevel];
while ( numLeftLine > 0 )
{
//start a new curve;
for (j=0; j<levelIndex[currentLevel]; j++)
{
if ( level[currentLevel][j].layer != OMITLINE)
{
isNewCurve = TRUE;
headLine = j;
currentLine = j;
break;
}
}
if ( !isNewCurve )
{
printf("error: can't establish new curve while still left line.\n");
exit(-2);
}
pHead = 0; /* head point position of new curve. */
pEnd = 1; /* end point position of new curve. */
currentCurvePos = *numLevelPoints;
levelCurvePos[*numLevelCurves] = currentCurvePos;
*numLevelPoints += 2; *numLevelCurves += 1;
levelCurves[currentCurvePos+pHead] = level[currentLevel][headLine].p1;
levelCurves[currentCurvePos+pEnd ] = level[currentLevel][headLine].p2;
currentLayer = level[currentLevel][headLine].layer;
level[currentLevel][headLine].layer = OMITLINE;
numLeftLine--;
isEndCurve = FALSE;
while ( (!isEndCurve) && (numLeftLine>0) )
{
/* find a nexeLine. */
for (j=0; j<levelIndex[currentLevel]; j++)
{
if ( level[currentLevel][j].layer != OMITLINE )
{
if ( isSamePoint(level[currentLevel][j].p1, levelCurves[currentCurvePos+pEnd]) )
{
if ( !isSamePoint(level[currentLevel][j].p2, levelCurves[currentCurvePos+pEnd-1]) )
{
pEnd++; /* add one point into currentCurve. */
(*numLevelPoints) ++;
levelCurves[currentCurvePos+pEnd] = level[currentLevel][j].p2;
level[currentLevel][j].layer = OMITLINE;
numLeftLine--;
}
else
{
/* omit the same line */
level[currentLevel][j].layer = OMITLINE;
numLeftLine--;
}
goto toNewFind;
}
else if ( isSamePoint(level[currentLevel][j].p2, levelCurves[currentCurvePos+pEnd]) )
{
if ( !isSamePoint(level[currentLevel][j].p1, levelCurves[currentCurvePos+pEnd-1]) )
{
pEnd++; /* add one point into currentCurve. */
(*numLevelPoints) ++;
levelCurves[currentCurvePos+pEnd] = level[currentLevel][j].p1;
level[currentLevel][j].layer = OMITLINE;
numLeftLine--;
}
else
{
/* omit the same line */
level[currentLevel][j].layer = OMITLINE;
numLeftLine--;
}
goto toNewFind;
}
}/* End of judgement OMITLAYER */
}/* End find a next line. */
isEndCurve = TRUE;
toNewFind:continue;
}/* End of currentLevel. */
}/* numLeftLine > 0 */
return 0;
}//End of makeLevelCurves().
long isSamePoint(POINT3D a, POINT3D b){
long isSame;
isSame = FALSE;
if ( fabs(fabs(a.x - b.x) + fabs(a.y - b.y) + fabs(a.z - b.z)) <= PRECISIONS )
isSame = TRUE;
return isSame;
}//End of isSamePoint().
long makeFaceSectionLine(long nump, POINT3D *node,
long numf, QFACE *face, long *layer,
double *levelBorder)
{
long i;
long faceNodeLevel[QFACEPoints];
long currentLayer;
for (i=0;i<numf;i++)
{
currentLayer = layer[i];
getFaceNodeLevels(node, face[i], levelBorder, faceNodeLevel, currentLayer);
makeSectionLine(node, face[i], faceNodeLevel, levelBorder, currentLayer);
}
return 0;
}//End of makeFaceSectionLine();
long makeSectionLine(POINT3D *node, QFACE currentFace,
long *faceNodeLevel, double *levelBorder,
long currentLayer)
{
long i, j, k;
long newLevelOrder[QFACEPoints];
long currentLevel;
EDGE eg[QFACEPoints];
long v[QFACEPoints];
POINT3D point[QFACEPoints];
long singlePoint;
v[0]=currentFace.v1; v[1]=currentFace.v2;
v[2]=currentFace.v3; v[3]=currentFace.v4;
eg[0].v1=v[0]; eg[0].v2=v[1];
eg[1].v1=v[1]; eg[1].v2=v[2];
eg[2].v1=v[2]; eg[2].v2=v[3];
eg[3].v1=v[3]; eg[3].v2=v[0];
setNodeLevelOrder(faceNodeLevel, newLevelOrder);
currentLevel=faceNodeLevel[newLevelOrder[0]];
for (k=faceNodeLevel[newLevelOrder[0]]; k>=faceNodeLevel[newLevelOrder[QFACEPoints-1]]; k--)
{
j=0L;
singlePoint = FALSE;
for (i=0;i<QFACEPoints;i++)
{
if (
( (node[eg[i].v1].z >= ( levelBorder[currentLevel] - PRECISIONS ) ) &&
(node[eg[i].v2].z <= ( levelBorder[currentLevel] + PRECISIONS ) ) )
||
( (node[eg[i].v1].z <= ( levelBorder[currentLevel] + PRECISIONS ) ) &&
(node[eg[i].v2].z >= ( levelBorder[currentLevel] - PRECISIONS ) ) )
)
{
if ( fabs(node[eg[i].v1].z-node[eg[i].v2].z)<=PRECISIONS )
{
point[j]=node[eg[i].v1];
point[j+1]=node[eg[i].v2];
j=0L;
insertLine(currentLayer, currentLevel, point[j], point[j+1]);
}
else
{
point[j] = getSectionPoint(node, levelBorder[currentLevel], eg[i]);
j++;
singlePoint = TRUE;
}
}
}
if (singlePoint && (j==2L) )
insertLine(currentLayer, currentLevel, point[0], point[1]);
currentLevel--;
}
return 0;
}//End of makeSectionLine();
long insertLine(long currentLayer, l
钱亚锋
- 粉丝: 107
- 资源: 1万+
最新资源
- S1017基于VUE+nodejs的点餐管理系统.zip
- 地理信息系统JTS库:空间分析与几何运算实现指南
- ESP8266+wifimanager库实现自动配网和时间天气显示
- windows计划任务python脚本调度器工具
- 产品销售网站源代码.zip
- 车辆管理系统源代码.zip
- S0079基于vue+SSM的“约球”足球类安卓app源码.zip
- win32汇编环境,对话框程序中复选框的一般操作示例
- 级联选择器,element-ui版本号 2.13.0
- VLC-Android-3.5.7-armeabi-v7a.apk
- sudo-1.9.16p2-1.ky10.x86-64.zip
- 3b113医疗用品销售网站_springboot+vue.zip
- 3b111研究生双选信息发布系统_springboot+vue.zip
- 3b112养老院管理系统_springboot+vue.zip
- 3b114医院病房信息管理系统_springboot+vue.zip
- 3b115基于JavaWeb的艺术摄影预约_springboot+vue0.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈