5 Star 22 Fork 10

geoda/geoda_mirror

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
GdaShape.h 20.14 KB
一键复制 编辑 原始数据 按行查看 历史
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
/**
* GeoDa TM, Copyright (C) 2011-2015 by Luc Anselin - all rights reserved
*
* This file is part of GeoDa.
*
* GeoDa is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GeoDa is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GEODA_CENTER_MY_SHAPE_H__
#define __GEODA_CENTER_MY_SHAPE_H__
#include <algorithm>
#include <wx/gdicmn.h>
#include <wx/brush.h>
#include <wx/pen.h>
#include <wx/dc.h>
#include <wx/graphics.h>
#include <wx/region.h>
#include <wx/string.h>
#include <cmath>
#include "Explore/Basemap.h"
#include "ShpFile.h"
#include "GenUtils.h"
#include "GdaConst.h"
class GdaPolygon;
struct GdaScaleTrans {
GdaScaleTrans();
GdaScaleTrans(double s_x, double s_y, double t_x, double t_y)
{
scale_x = s_x;
scale_y = s_y;
max_scale = std::max<double>(s_x, s_y);
trans_x = t_x;
trans_y = t_y;
slack_x = 0;
slack_y = 0;
}
virtual GdaScaleTrans& operator=(const GdaScaleTrans& s);
void SetData(double x_min, double y_min, double x_max, double y_max);
void SetView(int screen_w, int screen_h, double scale_factor=1.0);
void SetMargin(int _top_marg=GdaConst::default_virtual_screen_marg_top,
int _bottom_marg=GdaConst::default_virtual_screen_marg_bottom,
int _left_marg=GdaConst::default_virtual_screen_marg_left,
int _right_marg=GdaConst::default_virtual_screen_marg_right);
void calcAffineParams();
wxString GetString();
void transform_back(const wxPoint& src, wxRealPoint& result) const;
void transform(const wxRealPoint& src, wxPoint* result) const;
void transform(const wxRealPoint& src, wxRealPoint* result) const;
void transform(const wxPoint& src, wxPoint* result) const;
void transform(const Shapefile::Point& src, wxPoint* result) const;
void transform(const double& src, double* result) const;
void transform(const double& src, int* result) const;
wxRealPoint View2Data(const wxPoint& src);
bool IsValid();
void Reset();
void SetFixedAspectRatio(bool fixed);
void PanView(const wxPoint& pt_from, const wxPoint& pt_to);
void Zoom(bool is_zoomin, wxPoint& from, wxPoint& to);
void ScrollView(int scroll_x, int scroll_y);
void SetExtent(double w, double e, double s, double n);
int GetXNudge();
wxRealPoint GetDataCenter();
// attributes
bool fixed_aspect_ratio;
double drawing_area_width;
double drawing_area_height;
double drawing_area_ar;
double orig_data_x_min;
double orig_data_y_min;
double orig_data_x_max;
double orig_data_y_max;
double data_width;
double data_height;
double data_x_min;
double data_y_min;
double data_x_max;
double data_y_max;
double data_ar;
double screen_width;
double screen_height;
double left_margin;
double right_margin;
double top_margin;
double bottom_margin;
double scale_x;
double scale_y;
double max_scale; // max of scale_x, scale_y
double trans_x;
double trans_y;
double slack_x;
double slack_y;
};
namespace GdaShapeAlgs {
void partsToCount(const std::vector<wxInt32>& parts,
int total_points, int* count);
wxRealPoint calculateMeanCenter(GdaPolygon* poly);
wxRealPoint calculateMeanCenter(int n, wxRealPoint* pts);
wxRealPoint calculateMeanCenter(const std::vector<Shapefile::Point>& pts);
wxRealPoint calculateCentroid(GdaPolygon* poly);
wxRealPoint calculateCentroid(int n, wxRealPoint* pts);
wxRealPoint calculateCentroid(int n,
const std::vector<Shapefile::Point>& pts);
double calculateArea(int n, wxRealPoint* pts);
double calculateArea(int n, const std::vector<Shapefile::Point>& pts);
void createCirclePolygon(const wxPoint& center, double radius,
int num_points = 0,
wxPoint* pnts_array = 0,
int* pnts_array_size = 0);
wxRegion createCircleRegion(const wxPoint& center, double radius,
int num_points = 0,
wxPoint* pnts_array = 0,
int* pnts_array_size = 0);
wxRegion createLineRegion(wxPoint a, wxPoint b);
bool pointInPolygon(const wxPoint& pt, int n, const wxPoint* pts);
void getBoundingBoxOrig(const GdaPolygon* p, double& xmin,
double& ymin, double& xmax, double& ymax);
}
struct GdaShapeAttribs {
GdaShapeAttribs() : brush(*wxBLUE_BRUSH), pen(*wxBLACK_PEN),
x_nudge(0), y_nudge(0) {}
GdaShapeAttribs(const GdaShapeAttribs& s);
GdaShapeAttribs(const GdaShapeAttribs* s);
virtual GdaShapeAttribs& operator=(const GdaShapeAttribs& s);
virtual ~GdaShapeAttribs() {}
wxBrush brush;
wxPen pen;
int x_nudge;
int y_nudge;
};
class GdaShape {
public:
GdaShape();
GdaShape(const GdaShape& s);
virtual ~GdaShape();
virtual GdaShape* clone() = 0;
virtual GdaShape& operator=(const GdaShape& s);
virtual wxPoint getCentroid() { return center; }
virtual wxPoint getMeanCenter() { return center; }
virtual wxRealPoint getCentroidOrig() { return center_o; }
virtual wxRealPoint getMeanCenterOrig() { return center_o; }
/* used by selection on screen */
virtual void Offset(double dx, double dy) = 0;
virtual void Offset(int dx, int dy) = 0;
virtual void Update(wxPoint pt1, wxPoint pt2) {}
virtual bool pointWithin(const wxPoint& pt) { return false; };
virtual bool Contains(const wxPoint& pt) { return pointWithin(pt); };
virtual bool regionIntersect(const wxRegion& region) { return false; };
virtual void applyScaleTrans(const GdaScaleTrans& A);
virtual void projectToBasemap(Gda::Basemap* basemap, double scale_factor = 1.0);
virtual void paintSelf(wxDC& dc) = 0;
virtual void paintSelf(wxGraphicsContext* gc) = 0;
// calls allocAttribs if needed, a convenience function.
virtual void setNudge(int x_nudge, int y_nudge);
virtual void setPen(const wxPen& pen);
virtual void setBrush(const wxBrush& brush);
const wxPen& getPen();
const wxBrush& getBrush();
int getXNudge();
int getYNudge();
bool isNull() { return null_shape; }
wxPoint center;
// for selectable shapes, indicates which category shape belongs to
int category;
wxRealPoint center_o;
wxPoint bb_poly[5];
protected:
bool null_shape; // flag for an placeholder or empty shape
GdaShapeAttribs* attribs; // optional extra attributes
};
class GdaPoint: public GdaShape {
public:
int radius;
double radius_o;
bool adaptive_radius;
GdaPoint(); // creates a null shape
GdaPoint(const GdaPoint& s);
GdaPoint(wxRealPoint point_o_s);
GdaPoint(wxRealPoint point_o_s, wxDouble radius);
GdaPoint(double x_orig, double y_orig);
GdaPoint(double x_orig, double y_orig, double radius_o);
virtual ~GdaPoint() {}
virtual void Offset(double dx, double dy);
virtual void Offset(int dx, int dy);
virtual GdaPoint* clone() { return new GdaPoint(*this); }
virtual bool pointWithin(const wxPoint& pt);
virtual bool regionIntersect(const wxRegion& r);
virtual void applyScaleTrans(const GdaScaleTrans& A);
virtual void projectToBasemap(Gda::Basemap* basemap, double scale_factor = 1.0);
virtual void paintSelf(wxDC& dc);
virtual void paintSelf(wxGraphicsContext* gc);
double GetX();
double GetY();
void SetX(double x);
void SetY(double y);
void SetRadius(double r) {radius = r;}
};
class GdaCircle: public GdaShape {
public:
GdaCircle(); // creates a null shape
GdaCircle(const GdaCircle& s);
GdaCircle(wxRealPoint center_o_s, double radius_o_s,
bool scale_radius = false);
GdaCircle(wxPoint pt1, wxPoint pt2);
virtual ~GdaCircle() {}
virtual void Offset(double dx, double dy);
virtual void Offset(int dx, int dy);
virtual void Update(wxPoint pt1, wxPoint pt2);
virtual GdaCircle* clone() { return new GdaCircle(*this); }
virtual bool pointWithin(const wxPoint& pt);
virtual bool regionIntersect(const wxRegion& r);
virtual void applyScaleTrans(const GdaScaleTrans& A);
virtual void paintSelf(wxDC& dc);
virtual void paintSelf(wxGraphicsContext* gc);
//wxPoint center; // inherited from GdaShape
double radius;
bool scale_radius; // does radius change when affine trans applied?
protected:
//wxRealPoint center_o; // inherited from GdaShape
double radius_o;
};
class GdaRectangle: public GdaShape {
public:
GdaRectangle(); // creates a null shape
GdaRectangle(const GdaRectangle& s);
GdaRectangle(wxRealPoint lower_left_o_s, wxRealPoint upper_right_o_s);
GdaRectangle(wxPoint lower_left_o_s, wxPoint upper_right_o_s);
virtual ~GdaRectangle() {}
virtual GdaRectangle* clone() { return new GdaRectangle(*this); }
virtual void Offset(double dx, double dy);
virtual void Offset(int dx, int dy);
virtual void Update(wxPoint pt1, wxPoint pt2);
virtual bool pointWithin(const wxPoint& pt);
virtual bool regionIntersect(const wxRegion& r);
virtual void applyScaleTrans(const GdaScaleTrans& A);
virtual void projectToBasemap(Gda::Basemap* basemap, double scale_factor = 1.0);
virtual void paintSelf(wxDC& dc);
virtual void paintSelf(wxGraphicsContext* gc);
wxPoint lower_left;
wxPoint upper_right;
protected:
wxRealPoint lower_left_o;
wxRealPoint upper_right_o;
};
class GdaPolygon: public GdaShape {
public:
GdaPolygon(); // creates a null shape
GdaPolygon(const GdaPolygon& s);
GdaPolygon(int n_s, wxRealPoint* points_o_s);
GdaPolygon(Shapefile::PolygonContents* pc_s);
GdaPolygon(wxPoint& pt1, wxPoint& pt2);
virtual ~GdaPolygon();
virtual GdaPolygon* clone() { return new GdaPolygon(*this); }
virtual void Offset(double dx, double dy);
virtual void Offset(int dx, int dy);
virtual bool pointWithin(const wxPoint& pt);
virtual bool regionIntersect(const wxRegion& r);
virtual void applyScaleTrans(const GdaScaleTrans& A);
virtual void projectToBasemap(Gda::Basemap* basemap,
double scale_factor = 1.0);
static wxRealPoint CalculateCentroid(int n, wxRealPoint* pts);
virtual void paintSelf(wxDC& dc);
virtual void paintSelf(wxGraphicsContext* gc);
// All values in points array are the same. Can render render
// as a single point at points[0]
bool all_points_same;
wxPoint* points;
int n; // size of points array
int n_count; // size of count array
// Note: count array is different than PolygonContents::parts array
// count stores the number of points in each polygon part
// parts stores the index of the first point for each polygon
int* count;
// (pc == 0 && points_o !=0 ) || (pc != 0 && points_o ==0 )
Shapefile::PolygonContents* pc;
wxRealPoint* points_o;
wxRealPoint bb_ll_o; // bounding box lower left
wxRealPoint bb_ur_o; // bounding box upper right
};
class GdaPolyLine: public GdaShape {
public:
GdaPolyLine();
GdaPolyLine(const GdaPolyLine& s);
GdaPolyLine(int n_s, wxRealPoint* points_o_s);
GdaPolyLine(double x1, double y1, double x2, double y2);
GdaPolyLine(wxPoint pt1, wxPoint pt2);
GdaPolyLine(Shapefile::PolyLineContents* pc_s);
virtual GdaPolyLine& operator=(const GdaPolyLine& s);
virtual ~GdaPolyLine();
virtual GdaPolyLine* clone() { return new GdaPolyLine(*this); }
virtual void Offset(double dx, double dy);
virtual void Offset(int dx, int dy);
virtual void Update(wxPoint pt1, wxPoint pt2);
virtual bool pointWithin(const wxPoint& pt);
virtual bool regionIntersect(const wxRegion& r);
virtual void applyScaleTrans(const GdaScaleTrans& A);
virtual void projectToBasemap(Gda::Basemap* basemap, double scale_factor = 1);
virtual void paintSelf(wxDC& dc);
virtual void paintSelf(wxGraphicsContext* gc);
virtual wxString printDetails();
static wxRealPoint CalculateCentroid(int n, wxRealPoint* pts) {
return wxRealPoint(0,0);
}
public:
wxPoint* points;
int n; // size of points array
int n_count; // size of count array
int* count; // index into various parts of points array
// (pc == 0 && points_o !=0 ) || (pc != 0 && points_o ==0 )
Shapefile::PolyLineContents* pc;
wxRealPoint* points_o;
//wxRegion region;
int from;
int to;
};
class GdaSpline: public GdaShape {
public:
GdaSpline();
GdaSpline(const GdaSpline& s);
GdaSpline(const std::vector<wxRealPoint>& points_orig);
GdaSpline(const std::vector<double>& x_orig,
const std::vector<double>& y_orig);
GdaSpline(double x_orig_first, double y_orig_first,
const std::vector<double>& x_orig,
const std::vector<double>& y_orig,
double x_orig_last, double y_orig_last,
double x_trans=0.0, double y_trans=0.0,
double x_scale=1.0, double y_scale=1.0);
virtual void addExtensions(double x_orig_first, double y_orig_first,
const std::vector<double>& x_orig,
const std::vector<double>& y_orig,
double x_orig_last, double y_orig_last,
double x_trans=0.0, double y_trans=0.0,
double x_scale=1.0, double y_scale=1.0);
virtual void reInit(const std::vector<double>& x_orig,
const std::vector<double>& y_orig,
double x_trans=0.0, double y_trans=0.0,
double x_scale=1.0, double y_scale=1.0);
virtual GdaSpline& operator=(const GdaSpline& s);
virtual ~GdaSpline();
virtual GdaSpline* clone() { return new GdaSpline(*this); }
virtual void Offset(double dx, double dy);
virtual void Offset(int dx, int dy);
virtual bool pointWithin(const wxPoint& pt);
virtual bool regionIntersect(const wxRegion& r);
virtual void applyScaleTrans(const GdaScaleTrans& A);
virtual void paintSelf(wxDC& dc);
virtual void paintSelf(wxGraphicsContext* gc);
virtual wxString printDetails();
public:
wxPoint* points;
int n; // size of points array
wxRealPoint* points_o;
};
class GdaRay: public GdaShape {
public:
GdaRay(); // creates a null shape
GdaRay(const GdaRay& s);
GdaRay(wxRealPoint center_o_s, double degs_rot_cc_from_horiz_s,
int length_s);
virtual ~GdaRay() {}
virtual GdaRay* clone() { return new GdaRay(*this); }
virtual void Offset(double dx, double dy);
virtual void Offset(int dx, int dy);
virtual bool pointWithin(const wxPoint& pt);
virtual bool regionIntersect(const wxRegion& r);
virtual void applyScaleTrans(const GdaScaleTrans& A);
virtual void paintSelf(wxDC& dc);
virtual void paintSelf(wxGraphicsContext* gc);
//wxPoint center; // inherited from GdaShape
double degs_rot_cc_from_horiz;
int length; // length in pixels
protected:
//wxRealPoint center_o; // inherited from GdaShape
};
class GdaShapeText: public GdaShape {
public:
enum VertAlignment{ top, v_center, bottom };
enum HorizAlignment{ left, h_center, right };
GdaShapeText();
GdaShapeText(wxString text_s, wxFont font_s, const wxRealPoint& ref_pt_s,
double degs_rot_cc_from_horiz_s = 0,
HorizAlignment h_align = h_center, VertAlignment v_align = v_center,
int x_nudge = 0, int y_nudge = 0);
GdaShapeText(const GdaShapeText& s);
virtual GdaShapeText& operator=(const GdaShapeText& s);
virtual ~GdaShapeText() {}
virtual GdaShapeText* clone() { return new GdaShapeText(*this); }
virtual void Offset(double dx, double dy);
virtual void Offset(int dx, int dy);
virtual void GetSize(wxDC& dc, int& w, int& h);
virtual bool pointWithin(const wxPoint& pt);
virtual void applyScaleTrans(const GdaScaleTrans& A);
virtual void paintSelf(wxDC& dc);
virtual void paintSelf(wxGraphicsContext* gc);
virtual void projectToBasemap(Gda::Basemap* basemap, double scale_factor = 1);
static wxPoint calcRefPoint(wxDC& dc, const wxString& text,
const wxFont& font,
const wxRealPoint& ref_pt,
double degs_rot_cc_from_horiz = 0,
HorizAlignment h_align = h_center,
VertAlignment v_align = v_center);
double getDegsRotCcFromHoriz() { return degs_rot_cc_from_horiz; }
wxString getText() { return text; }
void setText(wxString t) { text = t; }
wxString text;
wxFont font;
wxPoint ref_pt;
HorizAlignment horiz_align;
VertAlignment vert_align;
bool hidden;
protected:
double degs_rot_cc_from_horiz;
double degs_rot_cc_from_horiz_o;
wxRealPoint ref_pt_o;
};
class GdaShapeTable : public GdaShape {
public:
struct CellAttrib {
wxColour color;
};
GdaShapeTable();
GdaShapeTable(const std::vector<wxString>& vals,
const std::vector<CellAttrib>& attributes,
int rows, int cols, wxFont font,
const wxRealPoint& ref_pt,
GdaShapeText::HorizAlignment horiz_align = GdaShapeText::h_center,
GdaShapeText::VertAlignment vert_align = GdaShapeText::v_center,
GdaShapeText::HorizAlignment cell_h_align = GdaShapeText::h_center,
GdaShapeText::VertAlignment cell_v_align = GdaShapeText::v_center,
int row_gap = 3, int col_gap = 10,
int x_nudge = 0, int y_nudge = 0);
GdaShapeTable(const GdaShapeTable& s);
virtual GdaShapeTable& operator=(const GdaShapeTable& s);
virtual ~GdaShapeTable() {}
virtual GdaShapeTable* clone() { return new GdaShapeTable(*this); }
virtual void Offset(double dx, double dy);
virtual void Offset(int dx, int dy);
virtual void applyScaleTrans(const GdaScaleTrans& A);
virtual void paintSelf(wxDC& dc);
virtual void paintSelf(wxGraphicsContext* gc);
virtual void GetSize(wxDC& dc, int& w, int& h);
bool hidden;
std::vector<wxString> vals;
std::vector<CellAttrib> attributes;
wxFont font;
int rows;
int cols;
int row_gap;
int col_gap;
wxRealPoint ref_pt;
GdaShapeText::HorizAlignment horiz_align;
GdaShapeText::VertAlignment vert_align;
GdaShapeText::HorizAlignment cell_h_align;
GdaShapeText::VertAlignment cell_v_align;
protected:
wxRealPoint ref_pt_o;
};
class GdaAxis: public GdaShape {
public:
GdaAxis();
GdaAxis(const GdaAxis& s);
GdaAxis(const wxString& caption_s,
const AxisScale& s,
const wxRealPoint& a_s,
const wxRealPoint& b_s,
int x_nudge = 0,
int y_nudge = 0,
bool inSubview = false);
GdaAxis(const wxString& caption_s,
const std::vector<wxString>& tic_labels_s,
const wxRealPoint& a_s,
const wxRealPoint& b_s,
int x_nudge = 0,
int y_nudge = 0);
virtual ~GdaAxis() {}
virtual GdaAxis* clone() { return new GdaAxis(*this); }
virtual void Offset(double dx, double dy);
virtual void Offset(int dx, int dy);
virtual void applyScaleTrans(const GdaScaleTrans& A);
virtual void paintSelf(wxDC& dc);
virtual void paintSelf(wxGraphicsContext* gc);
wxString getCaption() { return caption; }
void setCaption(const wxString& s) { caption = s; }
bool isHorizontal() { return is_horizontal; }
void hideScaleValues(bool hide) { hide_scale_values = hide; }
void hideCaption(bool hide) { hide_caption = hide; }
void autoDropScaleValues(bool enable) { auto_drop_scale_values = enable; }
void hideNegativeLabels(bool enable) { hide_negative_labels = enable; }
void moveOuterValTextInwards(bool enable) {
move_outer_val_text_inwards = enable; }
AxisScale scale;
std::vector<wxString> tic_labels;
wxPoint a, b;
wxString caption;
bool hidden;
wxFont font;
protected:
bool is_horizontal;
wxRealPoint a_o;
wxRealPoint b_o;
wxFont caption_font;
bool hide_scale_values;
bool hide_caption;
bool auto_drop_scale_values;
bool hide_negative_labels;
bool move_outer_val_text_inwards;
bool inSubview;
};
class GdaSelRegion {
public:
enum Type { rectangle, circle, line };
Type regionType;
int sel1;
int sel2;
};
/**
This class is used for pointer comparisons between GdaShape pointers. If
p1 and p2 are pointers to GdaShape instances, then p1 < p2 is true
if and only if p1->z < p2->z, where z is the z-value integer in each GdaShape
object.
This is only used to specify the std::multiset<GdaShape*, my_shp_ptr_comp>
template instance so that a multiset of GdaShape points has a well-defined
partial order.
*/
//class my_shp_ptr_comp { // used by multiset template for comparison
//public:
// bool operator() (const GdaShape* lhs, const GdaShape* rhs) const
// { return lhs->z < rhs->z; }
//};
#endif
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/geoda/geoda_mirror.git
[email protected]:geoda/geoda_mirror.git
geoda
geoda_mirror
geoda_mirror
master

搜索帮助