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 _MAKEGRAPH_C
37
#include "openaxiom-c-macros.h"
38
39
#include <stdlib.h>
40
#include <stdio.h>
41
42
#include "viewman.h"
43
44
#include "sockio.h"
45
#include "makeGraph.H1"
46
47
graphStruct *
48
makeGraphFromSpadData(void)
49
{
50
51
graphStruct *graphData;
52
pointListStruct *pL;
53
pointStruct *p;
54
int i,j;
55
56
if (!(graphData = (graphStruct *)malloc(sizeof(graphStruct)))) {
57
fprintf(stderr,"The viewport manager ran out of memory trying to create a new graph (graphStruct).\n");
58
exit(-1);
59
}
60
61
graphData->xmin = get_float(spadSock); /* after everything is normalized */
62
graphData->xmax = get_float(spadSock);
63
graphData->ymin = get_float(spadSock); /* view2D */
64
graphData->ymax = get_float(spadSock);
65
66
graphData->xNorm = 1/(graphData->xmax - graphData->xmin);
67
graphData->yNorm = 1/(graphData->ymax - graphData->ymin);
68
69
graphData->spadUnitX = get_float(spadSock);
70
graphData->spadUnitY = get_float(spadSock);
71
72
graphData->unitX = graphData->spadUnitX * graphData->xNorm;
73
graphData->unitY = graphData->spadUnitY * graphData->yNorm;
74
75
graphData->originX = -graphData->xmin * graphData->xNorm - 0.5;
76
graphData->originY = -graphData->ymin * graphData->yNorm - 0.5;
77
78
79
graphData->numberOfLists = get_int(spadSock);
80
if (!(pL = (pointListStruct *)malloc(graphData->numberOfLists * sizeof(pointListStruct)))) {
81
fprintf(stderr,"The viewport manager ran out of memory trying to create a new graph (pointListStruct).\n");
82
exit(-1);
83
}
84
graphData->listOfListsOfPoints = pL;
85
86
for (i=0; i<graphData->numberOfLists; i++) {
87
88
pL->numberOfPoints = get_int(spadSock);
89
if (!(p = (pointStruct *)malloc(pL->numberOfPoints * sizeof(pointStruct)))) {
90
fprintf(stderr,"The viewport manager ran out of memory trying to create a new graph (pointStruct).\n");
91
exit(-1);
92
}
93
pL->listOfPoints = p; /** point to current point list **/
94
95
for (j=0; j<pL->numberOfPoints; j++) {
96
p->x = get_float(spadSock); /* get numbers from OpenAxiom */
97
p->y = get_float(spadSock);
98
p->hue = get_float(spadSock) - 1; /* make zero based */
99
p->shade = get_float(spadSock) - 1;
100
/* normalize to range [-0.5..0.5] */
101
p->x = (p->x - graphData->xmin) * graphData->xNorm - 0.5;
102
p->y = (p->y - graphData->ymin) * graphData->yNorm - 0.5;
103
p++;
104
}
105
/* for now, getting hue, shade - do hue * totalHues + shade */
106
pL->pointColor = get_int(spadSock);
107
pL->lineColor = get_int(spadSock);
108
pL->pointSize = get_int(spadSock);
109
pL++; /** advance to next point list **/
110
}
111
112
113
graphData->key = graphKey++;
114
115
send_int(spadSock,(graphKey-1)); /* acknowledge to spad */
116
117
118
return(graphData);
119
120
}
121
122
123
void
124
discardGraph (graphStruct *theGraph)
125
{
126
127
pointListStruct *pL;
128
int j;
129
130
for (j=0, pL=theGraph->listOfListsOfPoints; j<theGraph->numberOfLists; j++,pL++)
131
free(pL->listOfPoints);
132
free(theGraph->listOfListsOfPoints);
133
free(theGraph);
134
135
}
136
137