LibreCAD
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
image.cpp
Go to the documentation of this file.
1 #include "image.h"
2 
3 
4 #include <algorithm>
6 #include "cad/geometry/geoarea.h"
7 
8 using namespace lc;
9 using namespace entity;
10 
11 Image::Image(const std::string &name,
12  const geo::Coordinate &base,
13  const geo::Coordinate &uv,
14  const geo::Coordinate &vv,
15  double width,
16  double height,
17  double brightness,
18  double contrast,
19  double fade,
20  const Layer_CSPtr layer,
21  const MetaInfo_CSPtr metaInfo,
22  const Block_CSPtr block) :
23  CADEntity(layer, metaInfo, block),
24  _name(name),
25  _base(base),
26  _uv(uv),
27  _vv(vv),
28  _width(width),
29  _height(height),
30  _brightness(brightness),
31  _contrast(contrast),
32  _fade(fade) {
33 
34 }
35 
36 Image::Image(const Image_CSPtr other, bool sameID) :
37  CADEntity(other, sameID), _name(other->_name), _base(other->_base), _uv(other->_uv), _vv(other->_vv), _width(other->_width), _height(other->_height),
38  _brightness(other->_brightness), _contrast(other->_contrast), _fade(other->_fade) {
39 }
40 
41 
42 std::vector<EntityCoordinate> Image::snapPoints(const geo::Coordinate& coord, const SimpleSnapConstrain & constrain, double minDistanceToSnap, int maxNumberOfSnapPoints) const {
43  std::vector<EntityCoordinate> points;
44 
45  if (constrain.constrain() & SimpleSnapConstrain::LOGICAL) {
46  // points.emplace_back(_bottomLeft, 0);
47  // points.emplace_back(_topRight, 1);
48  }
49 
50 
51  const geo::Coordinate npoe = nearestPointOnPath(coord);
53  points.emplace_back(npoe, 2);
54  }
55 
56  /*
57  if (constrain.constrain() & SimpleSnapConstrain::ON_ENTITY) {
58  if (this->nearestPointOnEntity(coord).distanceTo(coord)<minDistanceToSnap) {
59  points.emplace_back(npoe, 3);
60  }
61  }
62  */
63 
64  // Cleanup array of snappoints
65  Snapable::snapPointsCleanup(points, coord, maxNumberOfSnapPoints, minDistanceToSnap);
66 
67  return points;
68 }
69 
71  std::vector<geo::Coordinate> points;
72 /*
73  auto v1 = geo::Vector(_bottomLeft, geo::Coordinate(_bottomLeft.x(), _topRight.y()));
74  auto v2 = geo::Vector(_bottomLeft, geo::Coordinate(_topRight.x(), _bottomLeft.y()));
75  auto v3 = geo::Vector(_topRight, geo::Coordinate(_topRight.x(), _bottomLeft.y()));
76  auto v4 = geo::Vector(_topRight, geo::Coordinate(_bottomLeft.x(), _topRight.y()));
77 
78  points.push_back(v1.nearestPointOnEntity(coord));
79  points.push_back(v2.nearestPointOnEntity(coord));
80  points.push_back(v3.nearestPointOnEntity(coord));
81  points.push_back(v4.nearestPointOnEntity(coord));
82  std::sort(points.begin(), points.end(), geo::CoordinateDistanceSort(coord));
83 */
84  return geo::Coordinate();
85 }
86 
87 CADEntity_CSPtr Image::move(const geo::Coordinate& offset) const {
88  auto newImage = std::make_shared<Image>(_name, _base + offset, _uv, _vv, _width, _height, _brightness, _contrast, _fade, layer(), metaInfo());
89  newImage->setID(this->id());
90  return newImage;
91 }
92 
93 CADEntity_CSPtr Image::copy(const geo::Coordinate& offset) const {
94  auto newImage = std::make_shared<Image>(_name, _base + offset, _uv, _vv, _width, _height, _brightness, _contrast, _fade, layer(), metaInfo());
95  return newImage;
96 }
97 
98 CADEntity_CSPtr Image::rotate(const geo::Coordinate& rotation_center, const double rotation_angle) const {
99  // auto newImage = std::make_shared<Image>(_bottomLeft.rotate(rotation_center, rotation_angle),
100  // _topRight.rotate(rotation_center, rotation_angle), layer());
101  // newImage->setID(this->id());
102  return nullptr;
103 }
104 
105 CADEntity_CSPtr Image::scale(const geo::Coordinate& scale_center, const geo::Coordinate& scale_factor) const {
106  // auto newImage = std::make_shared<Image>(_bottomLeft.scale(scale_center, scale_factor),
107  // _topRight.scale(scale_center, scale_factor), layer());
108  //newImage->setID(this->id());
109  return nullptr;
110 }
111 
113  std::vector<geo::Coordinate> c;
114 // c.emplace_back(_base);
115 // c.emplace_back(_base.x(), _base.y() + _height);
116 // c.emplace_back(_base.x()+_width, _base.y() + _height);
117 // c.emplace_back(_base.x()+_width, _base.y());
118 
119  // Create 4 corners
120  c.emplace_back(0.,0.);
121  c.emplace_back(0., _height);
122  c.emplace_back(_width, _height);
123  c.emplace_back(_width, 0.);
124 
125  // Apply Transform
126  std::vector<geo::Coordinate> c2 = HelperMethods::transform2d<geo::Coordinate>(c, _uv.x(), _uv.y(), _vv.x(), _vv.y(), _base.x(), _base.y());
127 
128  // get bounding box
129  geo::Area area = geo::Area(c2.at(0), 0.,0.);
130  std::for_each(c2.begin(), c2.end(), [&](geo::Coordinate c) {area = area.merge(c);});
131 
132  return area;
133 }
134 
135 CADEntity_CSPtr Image::modify(Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo, Block_CSPtr block) const {
136  auto newImage = std::make_shared<Image>(
137  _name,
138  _base,
139  _uv,
140  _vv,
141  _width,
142  _height,
143  _brightness,
144  _contrast,
145  _fade,
146  layer,
147  metaInfo,
148  block
149  );
150  return newImage;
151 }
double _height
Definition: image.h:151
virtual CADEntity_CSPtr scale(const geo::Coordinate &scale_center, const geo::Coordinate &scale_factor) const override
scale, scales the entity
Definition: image.cpp:105
virtual CADEntity_CSPtr modify(Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo, Block_CSPtr block) const override
modify Return a new entity with the same ID bit with possible modified metainfo and/pr layer informat...
Definition: image.cpp:135
static const uint16_t LOGICAL
Definition: snapconstrain.h:22
double x() const
Returns x of Coordinate.
Definition: geocoordinate.h:26
virtual const geo::Area boundingBox() const override
boundingBox of the entity
Definition: image.cpp:112
geo::Coordinate _uv
Definition: image.h:148
static const uint16_t ON_ENTITYPATH
Definition: snapconstrain.h:19
double _fade
Brightness value, code 283, (0-100) default 0.
Definition: image.h:155
Layer_CSPtr layer() const
layer return the layer this entity is placed on
Definition: cadentity.cpp:29
double y() const
Returns y of Coordinate.
Definition: geocoordinate.h:34
virtual std::vector< EntityCoordinate > snapPoints(const geo::Coordinate &coord, const SimpleSnapConstrain &constrain, double minDistanceToSnap, int maxNumberOfSnapPoints) const override
Find a number of snap points the line has available This function returns a ordered list...
Definition: image.cpp:42
virtual CADEntity_CSPtr rotate(const geo::Coordinate &rotation_center, const double rotation_angle) const override
rotate, rotate operation
Definition: image.cpp:98
virtual CADEntity_CSPtr move(const geo::Coordinate &offset) const override
move, moves by an offset
Definition: image.cpp:87
MetaInfo_CSPtr metaInfo() const
Definition: cadentity.h:123
Image(const std::string &name, const geo::Coordinate &base, const geo::Coordinate &uv, const geo::Coordinate &vv, double width, double height, double brightness, double contrast, double fade, const Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo=nullptr, const Block_CSPtr block=nullptr)
Definition: image.cpp:11
Definition: cadentity.h:12
static void snapPointsCleanup(std::vector< EntityCoordinate > &points, const geo::Coordinate &reference, const unsigned int maxNumberOfSnapPoints, const double minDistanceToSnap)
Definition: snapable.h:53
geo::Coordinate _vv
Definition: image.h:149
std::string _name
Definition: image.h:146
Block_CSPtr block() const
Return the current entity block.
Definition: cadentity.cpp:33
double _brightness
Brightness value, code 281, (0-100) default 50.
Definition: image.h:153
virtual CADEntity_CSPtr copy(const geo::Coordinate &offset) const override
copy, copies Image by an offset
Definition: image.cpp:93
geo::Coordinate _base
Definition: image.h:147
double _width
Definition: image.h:150
virtual geo::Coordinate nearestPointOnPath(const geo::Coordinate &coord) const override
Find the nearest point on the path for this entity for the coordinate coord The path of a entity that...
Definition: image.cpp:70
const uint16_t constrain() const
Definition: snapconstrain.h:47
double _contrast
Brightness value, code 282, (0-100) default 50.
Definition: image.h:154