svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.geometry / org.gvsig.fmap.geometry.impl / src / main / java / org / gvsig / fmap / geom / primitive / impl / Envelope3D.java @ 41417
History | View | Annotate | Download (4.29 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
|
25 |
package org.gvsig.fmap.geom.primitive.impl; |
26 |
|
27 |
import org.cresques.cts.ICoordTrans; |
28 |
import org.gvsig.fmap.geom.primitive.Envelope; |
29 |
import org.gvsig.fmap.geom.primitive.Point; |
30 |
import org.gvsig.tools.ToolsLocator; |
31 |
import org.gvsig.tools.dynobject.DynStruct; |
32 |
import org.gvsig.tools.lang.Cloneable; |
33 |
import org.gvsig.tools.persistence.PersistenceManager; |
34 |
|
35 |
/**
|
36 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
|
37 |
*/
|
38 |
public class Envelope3D extends DefaultEnvelope implements Cloneable{ |
39 |
public static final String PERSISTENCE_DEFINITION_NAME = "Envelope3Dimensions"; |
40 |
private static final int DIMENSION = 3; |
41 |
private boolean isZInitilized =false; |
42 |
|
43 |
public Envelope3D() {
|
44 |
super();
|
45 |
} |
46 |
|
47 |
public Envelope3D(Point min, Point max) { |
48 |
super(min, max);
|
49 |
} |
50 |
|
51 |
/* (non-Javadoc)
|
52 |
* @see org.gvsig.fmap.geom.primitive.Envelope#getDimension()
|
53 |
*/
|
54 |
public int getDimension() { |
55 |
return DIMENSION;
|
56 |
} |
57 |
|
58 |
/*
|
59 |
* (non-Javadoc)
|
60 |
* @see org.gvsig.fmap.geom.primitive.Envelope#convert(org.cresques.cts.ICoordTrans)
|
61 |
*/
|
62 |
public Envelope convert(ICoordTrans trans) {
|
63 |
return null; |
64 |
} |
65 |
|
66 |
public static void registerPersistent() { |
67 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
68 |
if( manager.getDefinition(PERSISTENCE_DEFINITION_NAME)==null ) { |
69 |
DynStruct definition = manager.addDefinition( |
70 |
Envelope3D.class, |
71 |
PERSISTENCE_DEFINITION_NAME, |
72 |
"Envelope3D persistence definition",
|
73 |
null,
|
74 |
null
|
75 |
); |
76 |
|
77 |
definition.extend(manager.getDefinition(DefaultEnvelope.PERSISTENCE_DEFINITION_NAME)); |
78 |
} |
79 |
} |
80 |
|
81 |
public Object clone() throws CloneNotSupportedException { |
82 |
return super.clone(); |
83 |
} |
84 |
|
85 |
|
86 |
private void createPoints() { |
87 |
this.min = new Point2DZ(0, 0, 0); |
88 |
this.max = new Point2DZ(0, 0, 0); |
89 |
} |
90 |
|
91 |
public void add(Envelope envelope) { |
92 |
int i;
|
93 |
|
94 |
if( envelope==null && envelope.isEmpty() ) { |
95 |
return;
|
96 |
} |
97 |
|
98 |
int maxDimension = DIMENSION;
|
99 |
|
100 |
if( envelope.getDimension()==2 ) { |
101 |
maxDimension = 2;
|
102 |
} |
103 |
|
104 |
if( this.isZInitilized ) { |
105 |
for (i=0;i<maxDimension;i++){ |
106 |
this.min.setCoordinateAt(i,
|
107 |
Math.min(this.min.getCoordinateAt(i), envelope.getMinimum(i))); |
108 |
this.max.setCoordinateAt(i,
|
109 |
Math.max(this.max.getCoordinateAt(i), envelope.getMaximum(i))); |
110 |
} |
111 |
return;
|
112 |
} |
113 |
|
114 |
|
115 |
if (isEmpty){
|
116 |
createPoints(); |
117 |
if( maxDimension == 3 ) { |
118 |
this.isZInitilized = true; |
119 |
} |
120 |
for (i=0;i<maxDimension;i++){ |
121 |
this.min.setCoordinateAt(i, envelope.getMinimum(i));
|
122 |
this.max.setCoordinateAt(i, envelope.getMaximum(i));
|
123 |
} |
124 |
isEmpty = false;
|
125 |
} else {
|
126 |
if( maxDimension==DIMENSION ) {
|
127 |
this.min.setCoordinateAt(2, envelope.getMinimum(2)); |
128 |
this.max.setCoordinateAt(2, envelope.getMaximum(2)); |
129 |
this.isZInitilized = true; |
130 |
} |
131 |
for (i=0;i<maxDimension;i++){ |
132 |
this.min.setCoordinateAt(i,
|
133 |
Math.min(this.min.getCoordinateAt(i), envelope.getMinimum(i))); |
134 |
this.max.setCoordinateAt(i,
|
135 |
Math.max(this.max.getCoordinateAt(i), envelope.getMaximum(i))); |
136 |
} |
137 |
} |
138 |
} |
139 |
} |
140 |
|