root / trunk / org.gvsig.dwg / org.gvsig.dwg.lib / src / main / java / org / gvsig / dwg / lib / readers / v2004 / DwgSplineReader2004.java @ 5
History | View | Annotate | Download (6.11 KB)
1 |
/*
|
---|---|
2 |
* Created on 25-ene-2007 by azabala
|
3 |
*
|
4 |
*/
|
5 |
package org.gvsig.dwg.lib.readers.v2004; |
6 |
|
7 |
import java.util.ArrayList; |
8 |
|
9 |
import org.gvsig.dwg.lib.CorruptedDwgEntityException; |
10 |
import org.gvsig.dwg.lib.DwgObject; |
11 |
import org.gvsig.dwg.lib.DwgUtil; |
12 |
import org.gvsig.dwg.lib.objects.DwgSpline; |
13 |
import org.slf4j.Logger; |
14 |
import org.slf4j.LoggerFactory; |
15 |
|
16 |
|
17 |
/**
|
18 |
* @author alzabord
|
19 |
*
|
20 |
* TODO To change the template for this generated type comment go to
|
21 |
* Window - Preferences - Java - Code Style - Code Templates
|
22 |
*/
|
23 |
public class DwgSplineReader2004 extends AbstractDwg2004Reader{ |
24 |
|
25 |
private static Logger logger = LoggerFactory.getLogger(DwgSplineReader2004.class.getName()); |
26 |
|
27 |
/* (non-Javadoc)
|
28 |
* @see com.iver.cit.jdwglib.dwg.readers.IDwgObjectReader#readSpecificObj(int[], int, com.iver.cit.jdwglib.dwg.DwgObject)
|
29 |
*/
|
30 |
public void readSpecificObj(int[] data, int offset, DwgObject dwgObj) throws RuntimeException, CorruptedDwgEntityException { |
31 |
if(! (dwgObj instanceof DwgSpline)) |
32 |
throw new RuntimeException("DwgSplineReader2004 solo puede leer DwgSpline"); |
33 |
DwgSpline spline = (DwgSpline) dwgObj; |
34 |
int bitPos = offset;
|
35 |
bitPos = readObjectHeader(data, bitPos, spline); |
36 |
System.out.println("posActual = "+bitPos); |
37 |
ArrayList v;
|
38 |
v = DwgUtil.getBitShort(data, bitPos); |
39 |
bitPos = ((Integer)v.get(0)).intValue(); |
40 |
int sc = ((Integer)v.get(1)).intValue(); |
41 |
spline.setScenario(sc); |
42 |
|
43 |
v = DwgUtil.getBitShort(data, bitPos); |
44 |
bitPos = ((Integer)v.get(0)).intValue(); |
45 |
int deg = ((Integer)v.get(1)).intValue(); |
46 |
spline.setDegree(deg); |
47 |
|
48 |
int knotsNumber = 0; |
49 |
int controlPointsNumber = 0; |
50 |
int fitPointsNumber = 0; |
51 |
boolean weight = false; |
52 |
if (sc==2) { |
53 |
v = DwgUtil.getBitDouble(data, bitPos); |
54 |
bitPos = ((Integer)v.get(0)).intValue(); |
55 |
double ft = ((Double)v.get(1)).doubleValue(); |
56 |
spline.setFitTolerance(ft); |
57 |
|
58 |
v = DwgUtil.getBitDouble(data, bitPos); |
59 |
bitPos = ((Integer)v.get(0)).intValue(); |
60 |
double x = ((Double)v.get(1)).doubleValue(); |
61 |
v = DwgUtil.getBitDouble(data, bitPos); |
62 |
bitPos = ((Integer)v.get(0)).intValue(); |
63 |
double y = ((Double)v.get(1)).doubleValue(); |
64 |
v = DwgUtil.getBitDouble(data, bitPos); |
65 |
bitPos = ((Integer)v.get(0)).intValue(); |
66 |
double z = ((Double)v.get(1)).doubleValue(); |
67 |
double[] coord = new double[]{x, y, z}; |
68 |
spline.setBeginTanVector(coord); |
69 |
|
70 |
v = DwgUtil.getBitDouble(data, bitPos); |
71 |
bitPos = ((Integer)v.get(0)).intValue(); |
72 |
x = ((Double)v.get(1)).doubleValue(); |
73 |
v = DwgUtil.getBitDouble(data, bitPos); |
74 |
bitPos = ((Integer)v.get(0)).intValue(); |
75 |
y = ((Double)v.get(1)).doubleValue(); |
76 |
v = DwgUtil.getBitDouble(data, bitPos); |
77 |
bitPos = ((Integer)v.get(0)).intValue(); |
78 |
z = ((Double)v.get(1)).doubleValue(); |
79 |
coord = new double[]{x, y, z}; |
80 |
spline.setEndTanVector(coord); |
81 |
|
82 |
v = DwgUtil.getBitShort(data, bitPos); |
83 |
bitPos = ((Integer)v.get(0)).intValue(); |
84 |
fitPointsNumber = ((Integer)v.get(1)).intValue(); |
85 |
|
86 |
} else if (sc==1) { |
87 |
v = DwgUtil.testBit(data, bitPos); |
88 |
bitPos = ((Integer)v.get(0)).intValue(); |
89 |
boolean rat = ((Boolean)v.get(1)).booleanValue(); |
90 |
spline.setRational(rat); |
91 |
|
92 |
v = DwgUtil.testBit(data, bitPos); |
93 |
bitPos = ((Integer)v.get(0)).intValue(); |
94 |
boolean closed = ((Boolean)v.get(1)).booleanValue(); |
95 |
spline.setClosed(closed); |
96 |
|
97 |
v = DwgUtil.testBit(data, bitPos); |
98 |
bitPos = ((Integer)v.get(0)).intValue(); |
99 |
boolean per = ((Boolean)v.get(1)).booleanValue(); |
100 |
spline.setPeriodic(per); |
101 |
|
102 |
v = DwgUtil.getBitDouble(data, bitPos); |
103 |
bitPos = ((Integer)v.get(0)).intValue(); |
104 |
double ktol = ((Double)v.get(1)).doubleValue(); |
105 |
spline.setKnotTolerance(ktol); |
106 |
|
107 |
v = DwgUtil.getBitDouble(data, bitPos); |
108 |
bitPos = ((Integer)v.get(0)).intValue(); |
109 |
double ctol = ((Double)v.get(1)).doubleValue(); |
110 |
spline.setControlTolerance(ctol); |
111 |
|
112 |
v = DwgUtil.getBitLong(data, bitPos); |
113 |
bitPos = ((Integer)v.get(0)).intValue(); |
114 |
knotsNumber = ((Integer)v.get(1)).intValue(); |
115 |
|
116 |
v = DwgUtil.getBitLong(data, bitPos); |
117 |
bitPos = ((Integer)v.get(0)).intValue(); |
118 |
controlPointsNumber = ((Integer)v.get(1)).intValue(); |
119 |
|
120 |
v = DwgUtil.testBit(data, bitPos); |
121 |
bitPos = ((Integer)v.get(0)).intValue(); |
122 |
weight = ((Boolean)v.get(1)).booleanValue(); |
123 |
|
124 |
} else {
|
125 |
logger.warn("ERROR: Escenario desconocido");
|
126 |
} |
127 |
if (knotsNumber>0) { |
128 |
double[] knotpts = new double[knotsNumber]; |
129 |
for (int i=0;i<knotsNumber;i++) { |
130 |
v = DwgUtil.getBitDouble(data, bitPos); |
131 |
bitPos = ((Integer)v.get(0)).intValue(); |
132 |
knotpts[i] = ((Double)v.get(1)).doubleValue(); |
133 |
} |
134 |
spline.setKnotPoints(knotpts); |
135 |
} |
136 |
if (controlPointsNumber>0) { |
137 |
// Si el número de weights no coincide con el de ctrlpts habrá problemas ...
|
138 |
double[][] ctrlpts = new double[controlPointsNumber][3]; |
139 |
double[] weights = new double[controlPointsNumber]; |
140 |
for (int i=0;i<controlPointsNumber;i++) { |
141 |
v = DwgUtil.getBitDouble(data, bitPos); |
142 |
bitPos = ((Integer)v.get(0)).intValue(); |
143 |
double x = ((Double)v.get(1)).doubleValue(); |
144 |
v = DwgUtil.getBitDouble(data, bitPos); |
145 |
bitPos = ((Integer)v.get(0)).intValue(); |
146 |
double y = ((Double)v.get(1)).doubleValue(); |
147 |
v = DwgUtil.getBitDouble(data, bitPos); |
148 |
bitPos = ((Integer)v.get(0)).intValue(); |
149 |
double z = ((Double)v.get(1)).doubleValue(); |
150 |
ctrlpts[i][0] = x;
|
151 |
ctrlpts[i][1] = y;
|
152 |
ctrlpts[i][2] = z;
|
153 |
if (weight) {
|
154 |
v = DwgUtil.getBitDouble(data, bitPos); |
155 |
bitPos = ((Integer)v.get(0)).intValue(); |
156 |
weights[i] = ((Double)v.get(1)).doubleValue(); |
157 |
} |
158 |
} |
159 |
spline.setControlPoints(ctrlpts); |
160 |
if (weight) {
|
161 |
spline.setWeights(weights); |
162 |
} |
163 |
} |
164 |
if (fitPointsNumber>0) { |
165 |
double[][] fitpts = new double[fitPointsNumber][3]; |
166 |
for (int i=0;i<fitPointsNumber;i++) { |
167 |
v = DwgUtil.getBitDouble(data, bitPos); |
168 |
bitPos = ((Integer)v.get(0)).intValue(); |
169 |
double x = ((Double)v.get(1)).doubleValue(); |
170 |
v = DwgUtil.getBitDouble(data, bitPos); |
171 |
bitPos = ((Integer)v.get(0)).intValue(); |
172 |
double y = ((Double)v.get(1)).doubleValue(); |
173 |
v = DwgUtil.getBitDouble(data, bitPos); |
174 |
bitPos = ((Integer)v.get(0)).intValue(); |
175 |
double z = ((Double)v.get(1)).doubleValue(); |
176 |
fitpts[i][0] = x;
|
177 |
fitpts[i][1] = y;
|
178 |
fitpts[i][2] = z;
|
179 |
} |
180 |
spline.setFitPoints(fitpts); |
181 |
} |
182 |
bitPos = readObjectTailer(data, bitPos, spline); |
183 |
} |
184 |
|
185 |
} |