1f220fa62Smrg/*
2f220fa62Smrg** License Applicability. Except to the extent portions of this file are
3f220fa62Smrg** made subject to an alternative license as permitted in the SGI Free
4f220fa62Smrg** Software License B, Version 1.1 (the "License"), the contents of this
5f220fa62Smrg** file are subject only to the provisions of the License. You may not use
6f220fa62Smrg** this file except in compliance with the License. You may obtain a copy
7f220fa62Smrg** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
8f220fa62Smrg** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
9f220fa62Smrg**
10f220fa62Smrg** http://oss.sgi.com/projects/FreeB
11f220fa62Smrg**
12f220fa62Smrg** Note that, as provided in the License, the Software is distributed on an
13f220fa62Smrg** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
14f220fa62Smrg** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
15f220fa62Smrg** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
16f220fa62Smrg** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
17f220fa62Smrg**
18f220fa62Smrg** Original Code. The Original Code is: OpenGL Sample Implementation,
19f220fa62Smrg** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
20f220fa62Smrg** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
21f220fa62Smrg** Copyright in any portions created by third parties is as indicated
22f220fa62Smrg** elsewhere herein. All Rights Reserved.
23f220fa62Smrg**
24f220fa62Smrg** Additional Notice Provisions: The application programming interfaces
25f220fa62Smrg** established by SGI in conjunction with the Original Code are The
26f220fa62Smrg** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
27f220fa62Smrg** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
28f220fa62Smrg** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
29f220fa62Smrg** Window System(R) (Version 1.3), released October 19, 1998. This software
30f220fa62Smrg** was created using the OpenGL(R) version 1.2.1 Sample Implementation
31f220fa62Smrg** published by SGI, but has not been independently verified as being
32f220fa62Smrg** compliant with the OpenGL(R) version 1.2.1 Specification.
33f220fa62Smrg*/
34f220fa62Smrg
35f220fa62Smrg/*
36f220fa62Smrg *  reader.c++
37f220fa62Smrg *
38f220fa62Smrg */
39f220fa62Smrg
40f220fa62Smrg#include <stdio.h>
41f220fa62Smrg#include "glimports.h"
42f220fa62Smrg#include "nurbsconsts.h"
43f220fa62Smrg#include "reader.h"
44f220fa62Smrg#include "trimvertex.h"
45f220fa62Smrg#include "simplemath.h"
46f220fa62Smrg
47f220fa62Smrg//when read a pwlCurve, if two consecutive points are the same, then
48f220fa62Smrg//eliminate one of them. This makes the tessellator more robust. The spec
49f220fa62Smrg//assumes the application makes sure there are no redundant points.
50f220fa62Smrg//but in Inspector, the trim curves seem to have redundant points a lot.
51f220fa62Smrg//I guess other similar users may have the same problem.
52f220fa62Smrg
53f220fa62Smrg#define ELIMINATE_REDUNDANT_POINTS
54f220fa62Smrg
55f220fa62Smrg#ifdef  ELIMINATE_REDUNDANT_POINTS
56f220fa62Smrg#define equal(x,y) ( glu_abs(x-y) <= 0.00001)
57f220fa62Smrg#endif
58f220fa62Smrg
59f220fa62Smrg#ifdef ELIMINATE_REDUNDANT_POINTS
60f220fa62SmrgO_pwlcurve::O_pwlcurve( long _type, long count, INREAL *array, long byte_stride, TrimVertex *trimpts )
61f220fa62Smrg{
62f220fa62Smrg    next = 0;
63f220fa62Smrg    used = 0;
64f220fa62Smrg    owner = 0;
65f220fa62Smrg    pts = trimpts;
66f220fa62Smrg    npts = (int) count;
67f220fa62Smrg    save = 0;
68f220fa62Smrg    int i;
69f220fa62Smrg
70f220fa62Smrg    /* copy user data into internal trimming data structures */
71f220fa62Smrg    switch( _type ) {
72f220fa62Smrg        case N_P2D: {
73f220fa62Smrg	    TrimVertex *v = pts;
74f220fa62Smrg            TrimVertex *prev = NULL;
75f220fa62Smrg	    int num = 0;
76f220fa62Smrg	    int doit;
77f220fa62Smrg	    for(i=0; i<count; i++) {
78f220fa62Smrg	        doit = 1;
79f220fa62Smrg         	if(prev != NULL)
80f220fa62Smrg		  {
81f220fa62Smrg		    if(equal(prev->param[0], array[0]) && equal(prev->param[1], array[1]))
82f220fa62Smrg		      {
83f220fa62Smrg			doit = 0;
84f220fa62Smrg		      }
85f220fa62Smrg		  }
86f220fa62Smrg
87f220fa62Smrg		if(doit)
88f220fa62Smrg		  {
89f220fa62Smrg		    v->param[0] = (REAL) array[0];
90f220fa62Smrg		    v->param[1] = (REAL) array[1];
91f220fa62Smrg		    prev = v;
92f220fa62Smrg		    v++;
93f220fa62Smrg                    num++;
94f220fa62Smrg		  }
95f220fa62Smrg		array = (INREAL *) (((char *) array) + byte_stride);
96f220fa62Smrg	      }
97f220fa62Smrg	    npts = num;
98f220fa62Smrg	    break;
99f220fa62Smrg	}
100f220fa62Smrg        case N_P2DR: {
101f220fa62Smrg	    TrimVertex *v = pts;
102f220fa62Smrg    	    for( TrimVertex *lastv = v + count; v != lastv; v++ ) {
103f220fa62Smrg	        v->param[0] = (REAL) array[0] / (REAL) array[2];
104f220fa62Smrg	        v->param[1] = (REAL) array[1] / (REAL) array[2];
105f220fa62Smrg		array = (INREAL *) (((char *) array) + byte_stride);
106f220fa62Smrg	    }
107f220fa62Smrg	    break;
108f220fa62Smrg	}
109f220fa62Smrg    }
110f220fa62Smrg}
111f220fa62Smrg#else
112f220fa62SmrgO_pwlcurve::O_pwlcurve( long _type, long count, INREAL *array, long byte_stride, TrimVertex *trimpts )
113f220fa62Smrg{
114f220fa62Smrg    next = 0;
115f220fa62Smrg    used = 0;
116f220fa62Smrg    owner = 0;
117f220fa62Smrg    pts = trimpts;
118f220fa62Smrg    npts = (int) count;
119f220fa62Smrg    save = 0;
120f220fa62Smrg
121f220fa62Smrg    /* copy user data into internal trimming data structures */
122f220fa62Smrg    switch( _type ) {
123f220fa62Smrg        case N_P2D: {
124f220fa62Smrg	    TrimVertex *v = pts;
125f220fa62Smrg    	    for( TrimVertex *lastv = v + count; v != lastv; v++ ) {
126f220fa62Smrg	        v->param[0] = (REAL) array[0];
127f220fa62Smrg	        v->param[1] = (REAL) array[1];
128f220fa62Smrg		array = (INREAL *) (((char *) array) + byte_stride);
129f220fa62Smrg	    }
130f220fa62Smrg	    break;
131f220fa62Smrg	}
132f220fa62Smrg        case N_P2DR: {
133f220fa62Smrg	    TrimVertex *v = pts;
134f220fa62Smrg    	    for( TrimVertex *lastv = v + count; v != lastv; v++ ) {
135f220fa62Smrg	        v->param[0] = (REAL) array[0] / (REAL) array[2];
136f220fa62Smrg	        v->param[1] = (REAL) array[1] / (REAL) array[2];
137f220fa62Smrg		array = (INREAL *) (((char *) array) + byte_stride);
138f220fa62Smrg	    }
139f220fa62Smrg	    break;
140f220fa62Smrg	}
141f220fa62Smrg    }
142f220fa62Smrg}
143f220fa62Smrg#endif
144f220fa62Smrg
145f220fa62Smrg
146f220fa62Smrg
147f220fa62Smrg
148f220fa62Smrg
149