GEOS: precision.h Source File

- Main Page
- Namespaces
- Classes
- Files
- Related Pages

# precision.h

    00001 /**********************************************************************
    00002  * $Id: precision.h,v 1.4 2004/07/19 13:19:31 strk Exp $
    00003  *
    00004  * GEOS - Geometry Engine Open Source
    00005  * http://geos.refractions.net
    00006  *
    00007  * Copyright (C) 2001-2002 Vivid Solutions Inc.
    00008  *
    00009  * This is free software; you can redistribute and/or modify it under
    00010  * the terms of the GNU Lesser General Public Licence as published
    00011  * by the Free Software Foundation.
    00012  * See the COPYING file for more information.
    00013  *
    00014  **********************************************************************
    00015  * $Log: precision.h,v $
    00016  * Revision 1.4  2004/07/19 13:19:31  strk
    00017  * Documentation fixes
    00018  *
    00019  * Revision 1.3  2004/07/08 19:34:49  strk
    00020  * Mirrored JTS interface of CoordinateSequence, factory and
    00021  * default implementations.
    00022  * Added DefaultCoordinateSequenceFactory::instance() function.
    00023  *
    00024  * Revision 1.2  2004/07/06 17:58:22  strk
    00025  * Removed deprecated Geometry constructors based on PrecisionModel and
    00026  * SRID specification. Removed SimpleGeometryPrecisionReducer capability
    00027  * of changing Geometry's factory. Reverted Geometry::factory member
    00028  * to be a reference to external factory.
    00029  *
    00030  * Revision 1.1  2004/07/02 13:20:42  strk
    00031  * Header files moved under geos/ dir.
    00032  *
    00033  * Revision 1.4  2004/05/03 17:15:38  strk
    00034  * leaks on exception fixed.
    00035  *
    00036  * Revision 1.3  2004/04/20 08:52:01  strk
    00037  * GeometryFactory and Geometry const correctness.
    00038  * Memory leaks removed from SimpleGeometryPrecisionReducer
    00039  * and GeometryFactory.
    00040  *
    00041  * Revision 1.2  2004/04/13 13:31:11  strk
    00042  * prototype mismatch fixed
    00043  *
    00044  * Revision 1.1  2004/04/10 22:41:25  ybychkov
    00045  * "precision" upgraded to JTS 1.4
    00046  *
    00047  *
    00048  **********************************************************************/
    00049
    00050 #ifndef GEOS_PRECISION_H
    00051 #define GEOS_PRECISION_H
    00052
    00053 #include <geos/platform.h>
    00054 #include <geos/geom.h>
    00055 #include <geos/geomUtil.h>
    00056 #include <string>
    00057 #include <vector>
    00058
    00059 using namespace std;
    00060
    00061 namespace geos {
    00062
    00063 /*
    00064  * Determines the maximum number of common most-significant
    00065  * bits in the mantissa of one or numbers.
    00066  * Can be used to compute the double-precision number which
    00067  * is represented by the common bits.
    00068  * If there are no common bits, the number computed is 0.0.
    00069  *
    00070  */
    00071 class CommonBits {
    00072 private:
    00073         bool isFirst;
    00074         int commonMantissaBitsCount;
    00075         int64 commonBits;
    00076         int64 commonSignExp;
    00077 public:
    00084         static int64 signExpBits(int64 num);
    00094         static int numCommonMostSigMantissaBits(int64 num1, int64 num2);
    00101         static int64 zeroLowerBits(int64 bits, int nBits);
    00108         static int getBit(int64 bits, int i);
    00109         CommonBits();
    00110         void add(double num);
    00111         double getCommon();
    00115         string toString(int64 bits){return "";};
    00116 };
    00117
    00118 class CommonCoordinateFilter: public CoordinateFilter {
    00119 private:
    00120         CommonBits *commonBitsX;
    00121         CommonBits *commonBitsY;
    00122 public:
    00123         CommonCoordinateFilter();
    00124         ~CommonCoordinateFilter();
    00125         void filter_rw(Coordinate *coord);
    00126         void filter_ro(const Coordinate *coord);
    00127         Coordinate* getCommonCoordinate();
    00128 };
    00129
    00130 class Translater: public CoordinateFilter {
    00131 private:
    00132         Coordinate trans;
    00133 public:
    00134         Translater(Coordinate &newTrans);
    00135         void filter_rw(Coordinate *coord);
    00136         void filter_ro(const Coordinate *coord){}; //Not used
    00137 };
    00138
    00139 /*
    00140  * Allow computing and removing common mantissa bits from one or
    00141  * more Geometries.
    00142  *
    00143  */
    00144 class CommonBitsRemover {
    00145 private:
    00146         Coordinate commonCoord;
    00147         CommonCoordinateFilter *ccFilter;
    00148 public:
    00149         CommonBitsRemover();
    00150         ~CommonBitsRemover();
    00159         void add(Geometry *geom);
    00163         Coordinate& getCommonCoordinate();
    00171         Geometry* removeCommonBits(Geometry *geom);
    00179         void addCommonBits(Geometry *geom);
    00180 };
    00181
    00182 /*
    00183  * Provides versions of Geometry spatial functions which use
    00184  * common bit removal to reduce the likelihood of robustness problems.
    00185  * <p>
    00186  * In the current implementation no rounding is performed on the
    00187  * reshifted result geometry, which means that it is possible
    00188  * that the returned Geometry is invalid.
    00189  * Client classes should check the validity of the returned result themselves.
    00190  */
    00191 class CommonBitsOp {
    00192 private:
    00193         bool returnToOriginalPrecision;
    00194         CommonBitsRemover *cbr;
    00201         Geometry* removeCommonBits(Geometry *geom0);
    00210         vector<Geometry*>* removeCommonBits(Geometry *geom0, Geometry *geom1);
    00211 public:
    00215         CommonBitsOp();
    00222         CommonBitsOp(bool nReturnToOriginalPrecision);
    00229         Geometry* intersection(Geometry *geom0, Geometry *geom1);
    00236         Geometry* Union(Geometry *geom0, Geometry *geom1);
    00243         Geometry* difference(Geometry *geom0, Geometry *geom1);
    00251         Geometry* symDifference(Geometry *geom0, Geometry *geom1);
    00259         Geometry* buffer(Geometry *geom0, double distance);
    00270         Geometry* computeResultPrecision(Geometry *result);
    00271 };
    00272
    00273
    00274 /*
    00275  * Provides versions of Geometry spatial functions which use
    00276  * enhanced precision techniques to reduce the likelihood of robustness
    00277  * problems.
    00278  */
    00279 class EnhancedPrecisionOp {
    00280 public:
    00287         static Geometry* intersection(Geometry *geom0, Geometry *geom1);
    00294         static Geometry* Union(Geometry *geom0, Geometry *geom1);
    00301         static Geometry* difference(Geometry *geom0, Geometry *geom1);
    00308         static Geometry* symDifference(Geometry *geom0, Geometry *geom1);
    00318         static Geometry* buffer(Geometry *geom, double distance);
    00319 };
    00320
    00321 class SimpleGeometryPrecisionReducer;
    00322
    00323 class PrecisionReducerCoordinateOperation: public CoordinateOperation {
    00324 private:
    00325         SimpleGeometryPrecisionReducer *sgpr;
    00326 public:
    00327         PrecisionReducerCoordinateOperation(SimpleGeometryPrecisionReducer *newSgpr);
    00328         CoordinateSequence* edit(const CoordinateSequence *coordinates, const Geometry *geom);
    00329 };
    00330
    00331 /*
    00332  * Reduces the precision of a {@link Geometry}
    00333  * according to the supplied {@link PrecisionModel}, without
    00334  * attempting to preserve valid topology.
    00335  * <p>
    00336  * The topology of the resulting geometry may be invalid if
    00337  * topological collapse occurs due to coordinates being shifted.
    00338  * It is up to the client to check this and handle it if necessary.
    00339  * Collapses may not matter for some uses.  An example
    00340  * is simplifying the input to the buffer algorithm.
    00341  * The buffer algorithm does not depend on the validity of the input geometry.
    00342  *
    00343  */
    00344 class SimpleGeometryPrecisionReducer {
    00345 private:
    00346         PrecisionModel *newPrecisionModel;
    00347         bool removeCollapsed;
    00348         //bool changePrecisionModel;
    00349 public:
    00350         SimpleGeometryPrecisionReducer(PrecisionModel *pm);
    00358         void setRemoveCollapsedComponents(bool nRemoveCollapsed);
    00359
    00360         /*
    00361         * Sets whether the {@link PrecisionModel} of the new reduced Geometry
    00362         * will be changed to be the {@link PrecisionModel} supplied to
    00363         * specify the reduction.  The default is to not change the precision model
    00364         *
    00365         * @param changePrecisionModel if <code>true</code> the precision model of the created Geometry will be the
    00366         * the precisionModel supplied in the constructor.
    00367         */
    00368         //void setChangePrecisionModel(bool nChangePrecisionModel);
    00369
    00370         PrecisionModel* getPrecisionModel();
    00371
    00372         bool getRemoveCollapsed();
    00373         Geometry* reduce(const Geometry *geom);
    00374 };
    00375
    00376 }
    00377 #endif