SAGA API  v9.5
shape.cpp
Go to the documentation of this file.
1 
3 // //
4 // SAGA //
5 // //
6 // System for Automated Geoscientific Analyses //
7 // //
8 // Application Programming Interface //
9 // //
10 // Library: SAGA_API //
11 // //
12 //-------------------------------------------------------//
13 // //
14 // shape.cpp //
15 // //
16 // Copyright (C) 2005 by Olaf Conrad //
17 // //
18 //-------------------------------------------------------//
19 // //
20 // This file is part of 'SAGA - System for Automated //
21 // Geoscientific Analyses'. //
22 // //
23 // This library is free software; you can redistribute //
24 // it and/or modify it under the terms of the GNU Lesser //
25 // General Public License as published by the Free //
26 // Software Foundation, either version 2.1 of the //
27 // License, or (at your option) any later version. //
28 // //
29 // This library is distributed in the hope that it will //
30 // be useful, but WITHOUT ANY WARRANTY; without even the //
31 // implied warranty of MERCHANTABILITY or FITNESS FOR A //
32 // PARTICULAR PURPOSE. See the GNU Lesser General Public //
33 // License for more details. //
34 // //
35 // You should have received a copy of the GNU Lesser //
36 // General Public License along with this program; if //
37 // not, see <http://www.gnu.org/licenses/>. //
38 // //
39 //-------------------------------------------------------//
40 // //
41 // contact: Olaf Conrad //
42 // Institute of Geography //
43 // University of Goettingen //
44 // Goldschmidtstr. 5 //
45 // 37077 Goettingen //
46 // Germany //
47 // //
48 // e-mail: oconrad@saga-gis.org //
49 // //
51 
52 //---------------------------------------------------------
53 #include "shapes.h"
54 
55 
57 // //
58 // //
59 // //
61 
62 //---------------------------------------------------------
64  : CSG_Table_Record(pOwner, Index)
65 {}
66 
67 //---------------------------------------------------------
69 {
70  Destroy();
71 }
72 
73 
75 // //
77 
78 //---------------------------------------------------------
80 {}
81 
82 
84 // //
86 
87 //---------------------------------------------------------
89 {
90  return( ((CSG_Shapes *)m_pTable)->Get_Type() );
91 }
92 
93 //---------------------------------------------------------
95 {
96  return( ((CSG_Shapes *)m_pTable)->Get_Vertex_Type() );
97 }
98 
99 
101 // //
103 
104 //---------------------------------------------------------
105 inline void CSG_Shape::_Invalidate(void)
106 {
107  ((CSG_Shapes *)m_pTable)->Set_Update_Flag();
108 
109  Set_Modified();
110 }
111 
112 
114 // //
116 
117 //---------------------------------------------------------
119 {
120  if( !pShape || !Intersects(pShape->Get_Extent()) )
121  {
122  return( INTERSECTION_None );
123  }
124 
125  //-----------------------------------------------------
126  if( Get_Extent().is_Equal(pShape->Get_Extent()) && Get_Part_Count() == pShape->Get_Part_Count() && Get_Point_Count() == pShape->Get_Point_Count() )
127  {
128  bool bIdentical = true;
129 
130  for(int iPart=0; iPart<Get_Part_Count() && bIdentical; iPart++)
131  {
132  if( Get_Point_Count(iPart) != pShape->Get_Point_Count(iPart) )
133  {
134  bIdentical = false;
135  }
136  else for(int iPoint=0; iPoint<Get_Point_Count(iPart) && bIdentical; iPoint++)
137  {
138  CSG_Point Point(Get_Point(iPoint, iPart));
139 
140  if( !Point.is_Equal(pShape->Get_Point(iPoint, iPart)) )
141  {
142  bIdentical = false;
143  }
144  }
145  }
146 
147  if( bIdentical )
148  {
149  return( INTERSECTION_Identical );
150  }
151  }
152 
153  //-----------------------------------------------------
154  TSG_Intersection Intersection;
155 
156  if( Get_Type() >= pShape->Get_Type() && (Intersection = On_Intersects(pShape)) != INTERSECTION_None )
157  {
158  return( Intersection );
159  }
160 
161  Intersection = pShape->On_Intersects(this);
162 
163  if( Intersection == INTERSECTION_Contained )
164  {
165  return( INTERSECTION_Contains );
166  }
167 
168  if( Intersection == INTERSECTION_Contains )
169  {
170  return( INTERSECTION_Contained );
171  }
172 
173  return( Intersection );
174 }
175 
176 //---------------------------------------------------------
178 {
179  TSG_Intersection Intersection = Get_Extent().Intersects(Region);
180 
181  switch( Intersection )
182  {
183  default : return( Intersection );
185  case INTERSECTION_Overlaps: return( On_Intersects(Region) );
186  }
187 }
188 
189 
191 // //
193 
194 //---------------------------------------------------------
196 {
197  return( Assign(pRecord, SHAPE_COPY) );
198 }
199 
200 bool CSG_Shape::Assign(CSG_Table_Record *pRecord, bool bAssign_Attributes)
201 {
202  return( Assign(pRecord, bAssign_Attributes ? SHAPE_COPY : SHAPE_COPY_GEOM) );
203 }
204 
206 {
207  if( pRecord )
208  {
209  if( (mCopy == SHAPE_COPY || mCopy == SHAPE_COPY_GEOM) && pRecord->Get_Table()->Get_ObjectType() == SG_DATAOBJECT_TYPE_Shapes )
210  {
211  CSG_Shape *pShape = (CSG_Shape *)pRecord;
212 
213  if( Get_Type() == pShape->Get_Type() )
214  {
215  On_Assign(pShape);
216  }
217  }
218 
219  if( (mCopy == SHAPE_COPY || mCopy == SHAPE_COPY_ATTR) )
220  {
221  return( CSG_Table_Record::Assign(pRecord) );
222  }
223 
224  return( true );
225  }
226 
227  return( false );
228 }
229 
230 
232 // //
233 // //
234 // //
236 
237 //---------------------------------------------------------
SHAPE_COPY_ATTR
@ SHAPE_COPY_ATTR
Definition: shapes.h:127
TSG_Intersection
TSG_Intersection
Definition: geo_tools.h:101
CSG_Table_Record
Definition: table.h:130
CSG_Table::Get_ObjectType
virtual TSG_Data_Object_Type Get_ObjectType(void) const
Returns the object type as defined by TSG_Data_Object_Type. Used for run time type checking.
Definition: table.h:316
CSG_Table_Record::m_pTable
class CSG_Table * m_pTable
Definition: table.h:258
TSG_ADD_Shape_Copy_Mode
TSG_ADD_Shape_Copy_Mode
Definition: shapes.h:124
TSG_Shape_Type
TSG_Shape_Type
Definition: shapes.h:100
SHAPE_COPY_GEOM
@ SHAPE_COPY_GEOM
Definition: shapes.h:126
CSG_Table_Record::Assign
virtual bool Assign(CSG_Table_Record *pRecord)
Definition: table_record.cpp:543
INTERSECTION_Contains
@ INTERSECTION_Contains
Definition: geo_tools.h:106
CSG_Rect::Intersects
TSG_Intersection Intersects(const CSG_Rect &Rect) const
Definition: geo_classes.cpp:881
SHAPE_COPY
@ SHAPE_COPY
Definition: shapes.h:128
CSG_Shape::CSG_Shape
CSG_Shape(class CSG_Shapes *pOwner, sLong Index)
Definition: shape.cpp:63
CSG_Shape::Intersects
TSG_Intersection Intersects(CSG_Shape *pShape)
Definition: shape.cpp:118
CSG_Table_Record::Get_Table
class CSG_Table * Get_Table(void)
Definition: table.h:135
CSG_Shape::Get_Type
TSG_Shape_Type Get_Type(void) const
Definition: shape.cpp:88
SSG_Rect
Definition: geo_tools.h:464
CSG_Shape::Get_Point
virtual TSG_Point Get_Point(int iPoint=0) const =0
CSG_Shape::Destroy
virtual void Destroy(void)
Definition: shape.cpp:79
CSG_Shape::Get_Part_Count
virtual int Get_Part_Count(void) const =0
CSG_Point
Definition: geo_tools.h:135
INTERSECTION_None
@ INTERSECTION_None
Definition: geo_tools.h:102
CSG_Shape::Get_Vertex_Type
TSG_Vertex_Type Get_Vertex_Type(void) const
Definition: shape.cpp:94
sLong
signed long long sLong
Definition: api_core.h:158
INTERSECTION_Identical
@ INTERSECTION_Identical
Definition: geo_tools.h:103
CSG_Shape::Assign
virtual bool Assign(CSG_Table_Record *pRecord)
Definition: shape.cpp:195
CSG_Table_Record::Set_Modified
void Set_Modified(bool bOn=true)
Definition: table_record.cpp:220
SG_DATAOBJECT_TYPE_Shapes
@ SG_DATAOBJECT_TYPE_Shapes
Definition: dataobject.h:121
CSG_Shape::Get_Point_Count
virtual int Get_Point_Count(void) const =0
TSG_Vertex_Type
TSG_Vertex_Type
Definition: shapes.h:91
shapes.h
CSG_Shape::_Invalidate
virtual void _Invalidate(void)
Definition: shape.cpp:105
CSG_Shape::~CSG_Shape
virtual ~CSG_Shape(void)
Definition: shape.cpp:68
CSG_Shape::Get_Extent
virtual const CSG_Rect & Get_Extent(void)=0
CSG_Shapes
Definition: shapes.h:775
INTERSECTION_Contained
@ INTERSECTION_Contained
Definition: geo_tools.h:105
CSG_Point::is_Equal
virtual bool is_Equal(const CSG_Point &Point, double epsilon=0.) const
Definition: geo_tools.h:174
INTERSECTION_Overlaps
@ INTERSECTION_Overlaps
Definition: geo_tools.h:104
CSG_Shape
Definition: shapes.h:141
CSG_Shape::On_Intersects
virtual TSG_Intersection On_Intersects(CSG_Shape *pShape)=0
CSG_Shape::On_Assign
virtual bool On_Assign(CSG_Shape *pShape)=0