WhirlyGlobe  1.2
A 3D interactive globe toolkit for iOS
/Users/sjg/iPhone/WhirlyGlobe/WhirlyGlobeSrc/WhirlyGlobeLib/include/VectorData.h
00001 /*
00002  *  VectorData.h
00003  *  WhirlyGlobeLib
00004  *
00005  *  Created by Steve Gifford on 3/7/11.
00006  *  Copyright 2011 mousebird consulting
00007  *
00008  *  Licensed under the Apache License, Version 2.0 (the "License");
00009  *  you may not use this file except in compliance with the License.
00010  *  You may obtain a copy of the License at
00011  *  http://www.apache.org/licenses/LICENSE-2.0
00012  *
00013  *  Unless required by applicable law or agreed to in writing, software
00014  *  distributed under the License is distributed on an "AS IS" BASIS,
00015  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00016  *  See the License for the specific language governing permissions and
00017  *  limitations under the License.
00018  *
00019  */
00020 
00021 #import <math.h>
00022 #import <vector>
00023 #import <set>
00024 #import <boost/shared_ptr.hpp>
00025 #import <boost/pointer_cast.hpp>
00026 #import "Identifiable.h"
00027 #import "WhirlyVector.h"
00028 #import "WhirlyGeometry.h"
00029 
00030 namespace WhirlyGlobe
00031 {
00032         
00035 class VectorShape : public Identifiable
00036 {
00037 public: 
00039         void setAttrDict(NSMutableDictionary *newDict);
00040         
00042         NSMutableDictionary *getAttrDict();    
00044     virtual GeoMbr calcGeoMbr() = 0;
00045         
00046 protected:
00047         VectorShape();
00048         virtual ~VectorShape();
00049 
00050         NSMutableDictionary *attrDict;
00051 };
00052 
00053 class VectorAreal;
00054 class VectorLinear;
00055 class VectorPoints;
00056 
00058 typedef boost::shared_ptr<VectorShape> VectorShapeRef;
00060 typedef boost::shared_ptr<VectorAreal> VectorArealRef;
00062 typedef boost::shared_ptr<VectorLinear> VectorLinearRef;
00064 typedef boost::shared_ptr<VectorPoints> VectorPointsRef;
00065 
00067 typedef std::vector<Point2f> VectorRing;
00068 
00071 struct VectorShapeRefCmp
00072 {
00073     bool operator()(const VectorShapeRef &a,const VectorShapeRef &b)
00074     { return a.get() < b.get(); }
00075 };
00076   
00080 typedef std::set<VectorShapeRef,VectorShapeRefCmp> ShapeSet;
00081     
00083 float CalcLoopArea(const VectorRing &);
00084 
00087 class VectorAreal : public VectorShape
00088 {
00089 public:
00091     static VectorArealRef createAreal();
00092     ~VectorAreal();
00093     
00094     virtual GeoMbr calcGeoMbr();
00095     void initGeoMbr();
00096     
00098     bool pointInside(GeoCoord coord);
00099     
00101     void subdivide(float tolerance);
00102         
00103         GeoMbr geoMbr;
00104         std::vector<VectorRing> loops;
00105     
00106 protected:
00107     VectorAreal();
00108 };
00109 
00112 class VectorLinear : public VectorShape
00113 {
00114 public:
00116     static VectorLinearRef createLinear();
00117     ~VectorLinear();
00118     
00119     virtual GeoMbr calcGeoMbr();
00120     void initGeoMbr();
00121 
00123     void subdivide(float tolerance);
00124 
00125         GeoMbr geoMbr;
00126         VectorRing pts;
00127     
00128 protected:
00129     VectorLinear();
00130 };
00131 
00135 class VectorPoints : public VectorShape
00136 {
00137 public:
00139     static VectorPointsRef createPoints();
00140     ~VectorPoints();
00141     
00142     virtual GeoMbr calcGeoMbr();
00143     void initGeoMbr();
00144 
00145         GeoMbr geoMbr;
00146         VectorRing pts;
00147     
00148 protected:
00149     VectorPoints();
00150 };
00151     
00153 typedef std::set<std::string> StringSet;
00154     
00157 void SubdivideEdges(const VectorRing &inPts,VectorRing &outPts,bool closed,float maxLen);
00158 
00163 class VectorReader
00164 {
00165 public:
00166     VectorReader() { }
00167     virtual ~VectorReader() { }
00168         
00170     virtual bool isValid() = 0;
00171         
00175     virtual VectorShapeRef getNextObject(const StringSet *filter) = 0;
00176     
00178     virtual bool canReadByIndex() { return false; }
00179     
00181     virtual unsigned int getNumObjects() { return 0; }
00182     
00186     virtual VectorShapeRef getObjectByIndex(unsigned int vecIndex,const StringSet *filter)  { return VectorShapeRef(); }
00187 };
00188                         
00189 }