root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / FPolyline3DM.java @ 38563
History | View | Annotate | Download (3.67 KB)
1 |
package com.iver.cit.gvsig.fmap.core; |
---|---|
2 |
|
3 |
import java.awt.geom.PathIterator; |
4 |
|
5 |
import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
6 |
|
7 |
/**
|
8 |
* The Class FPolyline3DM that manages correctly (with Z and M) PolylineZs
|
9 |
*
|
10 |
* @author Pompermaier Flavio
|
11 |
*/
|
12 |
public class FPolyline3DM extends FPolyline3D implements FShapeM { |
13 |
|
14 |
private static final long serialVersionUID = -4920745174292188836L; |
15 |
private static final String NAME = "MULTILINESTRING_3DM"; |
16 |
double[] pM = null; |
17 |
|
18 |
/**
|
19 |
* Crea un nuevo Polyline3DM.
|
20 |
*
|
21 |
* @param gpx
|
22 |
* GeneralPathX
|
23 |
* @param pZ
|
24 |
* Vector con la Z.
|
25 |
* @param pM
|
26 |
* Vector con la M.
|
27 |
*/
|
28 |
public FPolyline3DM(GeneralPathX gpx, double[] pZ, double[] pM) { |
29 |
super(gpx, pZ);
|
30 |
this.pM = pM;
|
31 |
} |
32 |
|
33 |
/**
|
34 |
* @see com.iver.cit.gvsig.fmap.core.FShape#getShapeType()
|
35 |
*/
|
36 |
@Override
|
37 |
public int getShapeType() { |
38 |
return FShape.LINE | FShape.Z;
|
39 |
} |
40 |
|
41 |
/**
|
42 |
* Devuelve un Array con todos los valores de M.
|
43 |
*
|
44 |
* @return Array de Ms.
|
45 |
*/
|
46 |
public double[] getMs() { |
47 |
return pM;
|
48 |
} |
49 |
|
50 |
/*
|
51 |
* (non-Javadoc)
|
52 |
* @see com.iver.cit.gvsig.fmap.core.FShape#cloneFShape()
|
53 |
*/
|
54 |
@Override
|
55 |
public FShape cloneFShape() {
|
56 |
return new FPolyline3DM((GeneralPathX) gp.clone(), pZ, pM); |
57 |
} |
58 |
|
59 |
|
60 |
/*
|
61 |
* (non-Javadoc)
|
62 |
* @see com.iver.cit.gvsig.fmap.core.FShapeM#isDecreasing()
|
63 |
*/
|
64 |
public boolean isDecreasing() { |
65 |
if (pM.length == 0) |
66 |
return false; |
67 |
return pM[0] > pM[pM.length - 1]; |
68 |
} |
69 |
|
70 |
|
71 |
/*
|
72 |
* (non-Javadoc)
|
73 |
* @see com.iver.cit.gvsig.fmap.core.FShapeM#revertMs()
|
74 |
*/
|
75 |
public void revertMs() { |
76 |
double totalDistance = Math.abs(pM[0] - pM[pM.length - 1]); |
77 |
double[] percentages = new double[pM.length]; |
78 |
for (int i = 1; i < percentages.length; i++) { |
79 |
percentages[i] = Math.abs(pM[i] - pM[i - 1]) / totalDistance; |
80 |
} |
81 |
//The first value
|
82 |
double pm0 = pM[0]; |
83 |
if (!isDecreasing()) {
|
84 |
pM[0] = pM[pM.length - 1]; |
85 |
for (int i = 1; i < pM.length - 1; i++) { |
86 |
double increasing = percentages[i] * totalDistance;
|
87 |
pM[i] = pM[i - 1] - increasing;
|
88 |
} |
89 |
} |
90 |
else {
|
91 |
pM[0] = pM[pM.length - 1]; |
92 |
for (int i = 1; i < pM.length - 1; i++) { |
93 |
double decreasing = percentages[i] * totalDistance;
|
94 |
pM[i] = pM[i - 1] + decreasing;
|
95 |
} |
96 |
} |
97 |
pM[pM.length - 1] = pm0;
|
98 |
|
99 |
} |
100 |
|
101 |
|
102 |
/*
|
103 |
* (non-Javadoc)
|
104 |
* @see com.iver.cit.gvsig.fmap.core.FShapeM#setMAt(int, double)
|
105 |
*/
|
106 |
public void setMAt(int i, double value) { |
107 |
if (i < pM.length) {
|
108 |
pM[i] = value; |
109 |
} |
110 |
|
111 |
} |
112 |
|
113 |
|
114 |
/*
|
115 |
* (non-Javadoc)
|
116 |
* @see com.iver.cit.gvsig.fmap.core.FShapeM#toText()
|
117 |
*/
|
118 |
public String toText() { |
119 |
StringBuffer str = new StringBuffer(); |
120 |
str.append(NAME); |
121 |
str.append(" ((");
|
122 |
int theType;
|
123 |
double[] theData = new double[6]; |
124 |
|
125 |
PathIterator theIterator = getPathIterator(null, FConverter.FLATNESS); |
126 |
int i = 0; |
127 |
|
128 |
while (!theIterator.isDone()) {
|
129 |
//while not done
|
130 |
theType = theIterator.currentSegment(theData); |
131 |
|
132 |
double m = 0.0; |
133 |
if (i < pM.length) {
|
134 |
m = pM[i]; |
135 |
} |
136 |
|
137 |
switch (theType) {
|
138 |
case PathIterator.SEG_MOVETO: |
139 |
str.append(theData[0] + " " + theData[1] + " " + m + ","); |
140 |
break;
|
141 |
|
142 |
case PathIterator.SEG_LINETO: |
143 |
str.append(theData[0] + " " + theData[1] + " " + m + ","); |
144 |
|
145 |
break;
|
146 |
|
147 |
case PathIterator.SEG_QUADTO: |
148 |
System.out.println("Not supported here"); |
149 |
|
150 |
break;
|
151 |
|
152 |
case PathIterator.SEG_CUBICTO: |
153 |
System.out.println("Not supported here"); |
154 |
|
155 |
break;
|
156 |
|
157 |
case PathIterator.SEG_CLOSE: |
158 |
break;
|
159 |
} //end switch
|
160 |
|
161 |
theIterator.next(); |
162 |
i++; |
163 |
} //end while loop
|
164 |
return str.delete(str.length() - 1, str.length()) + "))"; |
165 |
} |
166 |
} |