Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

open-axiom repository from github

24005 views
1
/*
2
Copyright (C) 1991-2002, The Numerical ALgorithms Group Ltd.
3
All rights reserved.
4
Copyright (C) 2007-2008, Gabriel Dos Reis.
5
All rights reserved.
6
7
Redistribution and use in source and binary forms, with or without
8
modification, are permitted provided that the following conditions are
9
met:
10
11
- Redistributions of source code must retain the above copyright
12
notice, this list of conditions and the following disclaimer.
13
14
- Redistributions in binary form must reproduce the above copyright
15
notice, this list of conditions and the following disclaimer in
16
the documentation and/or other materials provided with the
17
distribution.
18
19
- Neither the name of The Numerical ALgorithms Group Ltd. nor the
20
names of its contributors may be used to endorse or promote products
21
derived from this software without specific prior written permission.
22
23
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
24
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
26
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
27
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
*/
35
36
#define _MAKE3D_C
37
#include "openaxiom-c-macros.h"
38
39
#include <stdlib.h>
40
41
#include "viewman.h"
42
#include "mode.h"
43
44
#include "sockio.h"
45
#include "make3D.H1"
46
47
void
48
makeView3DFromSpadData(view3DStruct *viewdata,int typeOfViewport)
49
{
50
51
int i,j,k;
52
LLPoint *anLLPoint;
53
LPoint *anLPoint;
54
int *anIndex;
55
int firstPieceOfData = yes;
56
int constantColor;
57
double cMin = 0;
58
double cMax = 0;
59
double cNorm = 0;
60
61
viewdata->typeOf3D = typeOfViewport;
62
63
viewdata->title = get_string(spadSock);
64
65
viewdata->deltaX = get_float(spadSock);
66
viewdata->deltaY = get_float(spadSock);
67
viewdata->scale = get_float(spadSock);
68
viewdata->scaleX = get_float(spadSock);
69
viewdata->scaleY = get_float(spadSock);
70
viewdata->scaleZ = get_float(spadSock);
71
viewdata->theta = get_float(spadSock);
72
viewdata->phi = get_float(spadSock);
73
74
viewdata->vX = get_int(spadSock);
75
viewdata->vY = get_int(spadSock);
76
viewdata->vW = get_int(spadSock);
77
viewdata->vH = get_int(spadSock);
78
79
viewdata->showCP = get_int(spadSock);
80
viewdata->style = get_int(spadSock);
81
viewdata->AxesOn = get_int(spadSock);
82
viewdata->diagonals = get_int(spadSock);
83
viewdata->outlineRenderOn = get_int(spadSock);
84
viewdata->box = get_int(spadSock);
85
viewdata->clipbox = get_int(spadSock);
86
viewdata->clipStuff = get_int(spadSock);
87
88
viewdata->hueOff = get_int(spadSock);
89
viewdata->numOfHues = get_int(spadSock);
90
91
viewdata->lightVec[0] = get_float(spadSock);
92
viewdata->lightVec[1] = get_float(spadSock);
93
viewdata->lightVec[2] = get_float(spadSock);
94
viewdata->translucency = get_float(spadSock);
95
96
viewdata->perspective = get_int(spadSock);
97
viewdata->eyeDistance = get_float(spadSock);
98
99
viewdata->numOfPoints = get_int(spadSock);
100
viewdata->points = (viewTriple *)malloc(viewdata->numOfPoints * sizeof(viewTriple));
101
for (i=0; i<viewdata->numOfPoints; i++) {
102
refPt(*viewdata,i)->x = get_float(spadSock);
103
refPt(*viewdata,i)->y = get_float(spadSock);
104
refPt(*viewdata,i)->z = get_float(spadSock);
105
refPt(*viewdata,i)->c = get_float(spadSock);
106
/* set min/max values */
107
if (firstPieceOfData) {
108
firstPieceOfData = no;
109
viewdata->xmin = viewdata->xmax = refPt(*viewdata,i)->x;
110
viewdata->ymin = viewdata->ymax = refPt(*viewdata,i)->y;
111
viewdata->zmin = viewdata->zmax = refPt(*viewdata,i)->z;
112
cMin = cMax = refPt(*viewdata,i)->c;
113
} else {
114
if (refPt(*viewdata,i)->x < viewdata->xmin) viewdata->xmin = refPt(*viewdata,i)->x;
115
else if (refPt(*viewdata,i)->x > viewdata->xmax) viewdata->xmax = refPt(*viewdata,i)->x;
116
if (refPt(*viewdata,i)->y < viewdata->ymin) viewdata->ymin = refPt(*viewdata,i)->y;
117
else if (refPt(*viewdata,i)->y > viewdata->ymax) viewdata->ymax = refPt(*viewdata,i)->y;
118
if (refPt(*viewdata,i)->z < viewdata->zmin) viewdata->zmin = refPt(*viewdata,i)->z;
119
else if (refPt(*viewdata,i)->z > viewdata->zmax) viewdata->zmax = refPt(*viewdata,i)->z;
120
if (refPt(*viewdata,i)->c < cMin) cMin = refPt(*viewdata,i)->c;
121
else if (refPt(*viewdata,i)->c > cMax) cMax = refPt(*viewdata,i)->c;
122
} /* if (firstPieceOfData) else */
123
} /* for i (point data) */
124
125
viewdata->lllp.numOfComponents = get_int(spadSock);
126
anLLPoint = viewdata->lllp.llp =
127
(LLPoint *)malloc(viewdata->lllp.numOfComponents*sizeof(LLPoint));
128
for (i=0; i<viewdata->lllp.numOfComponents; i++,anLLPoint++) {
129
anLLPoint->prop.closed = get_int(spadSock);
130
anLLPoint->prop.solid = get_int(spadSock);
131
anLLPoint->numOfLists = get_int(spadSock);
132
anLPoint = anLLPoint->lp =
133
(LPoint *)malloc(anLLPoint->numOfLists*sizeof(LPoint));
134
for (j=0; j<anLLPoint->numOfLists; j++,anLPoint++) {
135
anLPoint->prop.closed = get_int(spadSock);
136
anLPoint->prop.solid = get_int(spadSock);
137
anLPoint->numOfPoints = get_int(spadSock);
138
anIndex = anLPoint->indices =
139
(int *)malloc(anLPoint->numOfPoints*sizeof(int));
140
for (k=0; k<anLPoint->numOfPoints; k++,anIndex++)
141
*anIndex = get_int(spadSock);
142
} /* for LPoints in LLPoints (j) */
143
} /* for LLPoints in LLLPoints (i) */
144
145
/* now normalize the colors */
146
cNorm = cMax - cMin;
147
/*** new fields - cmin, cmax ***/
148
viewdata->cmin = cMin;
149
viewdata->cmax = cMax;
150
151
constantColor = (cNorm < 0.0001);
152
for (i=0; i<viewdata->numOfPoints; i++)
153
if (constantColor) refPt(*viewdata,i)->c = 0.5;
154
else refPt(*viewdata,i)->c = (refPt(*viewdata,i)->c - cMin)/cNorm;
155
156
viewdata->scaleDown = yes;
157
158
}
159
160
161