00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "ImageFeatures.h"
00022
00023 namespace cmlabs {
00024
00025 ImageFeature::ImageFeature() {}
00026 ImageFeature::~ImageFeature() {}
00027
00028
00029
00030
00031
00032
00033
00034
00035 ImagePointFeature::ImagePointFeature(JString creatorName, JTime t, double depth) {
00036 featureType = FEATURE_POINT;
00037 creator = creatorName;
00038 frameTime = t;
00039 planeDepth = depth;
00040 }
00041
00042 ImagePointFeature::~ImagePointFeature() {
00043 }
00044
00045 ImagePointFeature::ImagePointFeature(JString xml) {
00046 if (!Object::fromXML(xml)) {
00047 }
00048 }
00049
00050 ImagePointFeature::ImagePointFeature(XMLNode* node) {
00051 if (!fromXML(node)) {
00052 }
00053 }
00054
00055 Object* ImagePointFeature::clone() const {
00056 ImagePointFeature* p = new ImagePointFeature(creator, frameTime, planeDepth);
00057 *p = *this;
00058 return p;
00059 }
00060
00061 PointFloat ImagePointFeature::getPoint() {
00062 return point;
00063 }
00064
00065 Color ImagePointFeature::getColor() {
00066 return color;
00067 }
00068
00069 bool ImagePointFeature::setPoint(PointFloat p) {
00070 point = p;
00071 return true;
00072 }
00073
00074 bool ImagePointFeature::setColor(Color c) {
00075 color = c;
00076 return true;
00077 }
00078
00079 JString ImagePointFeature::print() {
00080 return JString::format("PointFeature: Point:%s Color:%s", (char*) point.print(), (char*) color.print());
00081 }
00082
00083 JString ImagePointFeature::toXML() {
00084 return JString::format("<pointfeature>\n%s%s</pointfeature>", (char*) point.toXML().indentXML(), (char*) color.toXML().indentXML());
00085 }
00086
00087 bool ImagePointFeature::fromXML(XMLNode* node) {
00088 if (node == NULL) {
00089 return false;
00090 }
00091 if (!node->getTag().equalsIgnoreCase("pointfeature"))
00092 return false;
00093
00094 XMLNode* xmlNode = node->getChildNode("pointfloat");
00095 if (xmlNode == NULL) return false;
00096 point.fromXML(xmlNode);
00097 xmlNode = node->getChildNode("color");
00098 if (xmlNode == NULL) return false;
00099 color.fromXML(xmlNode);
00100
00101 return true;
00102 }
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 ImageLineFeature::ImageLineFeature(JString creatorName, JTime t, double depth) {
00118 featureType = FEATURE_LINE;
00119 creator = creatorName;
00120 frameTime = t;
00121 planeDepth = depth;
00122 }
00123
00124 ImageLineFeature::~ImageLineFeature() {
00125 }
00126
00127 ImageLineFeature::ImageLineFeature(JString xml) {
00128 if (!Object::fromXML(xml)) {
00129 }
00130 }
00131
00132 ImageLineFeature::ImageLineFeature(XMLNode* node) {
00133 if (!fromXML(node)) {
00134 }
00135 }
00136
00137 Object* ImageLineFeature::clone() const {
00138 ImageLineFeature* l = new ImageLineFeature(creator, frameTime, planeDepth);
00139 *l = *this;
00140 return l;
00141 }
00142
00143 Line ImageLineFeature::getLine() {
00144 return line;
00145 }
00146
00147 Color ImageLineFeature::getAverageColor() {
00148 return colorAverage;
00149 }
00150
00151 Color ImageLineFeature::getColorStartPoint() {
00152 return colorStartPoint;
00153 }
00154
00155 Color ImageLineFeature::getColorEndPoint() {
00156 return colorEndPoint;
00157 }
00158
00159 Color ImageLineFeature::getColorLeftEdge() {
00160 return colorLeftEdge;
00161 }
00162
00163 Color ImageLineFeature::getColorRightEdge() {
00164 return colorRightEdge;
00165 }
00166
00167 bool ImageLineFeature::setColor(Color c) {
00168 colorAverage = c;
00169 return true;
00170 }
00171
00172 bool ImageLineFeature::setColor(Color colorAtStartPoint, Color colorAtEndPoint) {
00173 colorStartPoint = colorAtStartPoint;
00174 colorEndPoint = colorAtEndPoint;
00175 int red = (colorAtStartPoint.r + colorAtEndPoint.r) / 2;
00176 int green = (colorAtStartPoint.g + colorAtEndPoint.g) / 2;
00177 int blue = (colorAtStartPoint.b + colorAtEndPoint.b) / 2;
00178 colorAverage = Color(red, green, blue);
00179 return true;
00180 }
00181
00182 bool ImageLineFeature::setColor(Color colorAtStartPoint, Color colorAtEndPoint, Color colorAtLeftEdge, Color colorAtRightEdge) {
00183 colorStartPoint = colorAtStartPoint;
00184 colorEndPoint = colorAtEndPoint;
00185 colorLeftEdge = colorAtLeftEdge;
00186 colorRightEdge = colorAtRightEdge;
00187 int red = (colorAtStartPoint.r + colorAtEndPoint.r + colorAtLeftEdge.r + colorAtRightEdge.r) / 4;
00188 int green = (colorAtStartPoint.g + colorAtEndPoint.g + colorAtLeftEdge.g + colorAtRightEdge.g) / 4;
00189 int blue = (colorAtStartPoint.b + colorAtEndPoint.b + colorAtLeftEdge.b + colorAtRightEdge.b) / 4;
00190 colorAverage = Color(red, green, blue);
00191 return true;
00192 }
00193
00194
00195 JString ImageLineFeature::print() {
00196 return JString::format("LineFeature: Line:%s AvgColor:%s", (char*) line.print(), (char*) colorAverage.print());
00197 }
00198
00199 JString ImageLineFeature::toXML() {
00200 JString col1 = JString::format("<startpointcolor>\n%s</startpointcolor>\n", (char*) colorStartPoint.toXML().indentXML());
00201 JString col2 = JString::format("<endpointcolor>\n%s</endpointcolor>\n", (char*) colorEndPoint.toXML().indentXML());
00202 JString col3 = JString::format("<leftedgecolor>\n%s</leftedgecolor>\n", (char*) colorLeftEdge.toXML().indentXML());
00203 JString col4 = JString::format("<rightedgecolor>\n%s</rightedgecolor>\n", (char*) colorRightEdge.toXML().indentXML());
00204 return JString::format("<linefeature>\n%s%s%s%s%s%s</linefeature>", (char*) line.toXML().indentXML(), (char*) colorAverage.toXML().indentXML(), (char*) col1.indentXML(), (char*) col2.indentXML(), (char*) col3.indentXML(), (char*) col4.indentXML());
00205 }
00206
00207 bool ImageLineFeature::fromXML(XMLNode* node) {
00208 if (node == NULL) {
00209 return false;
00210 }
00211 if (!node->getTag().equalsIgnoreCase("linefeature"))
00212 return false;
00213
00214 XMLNode* xmlNode;
00215 XMLNode* subNode;
00216
00217 xmlNode = node->getChildNode("line");
00218 if (xmlNode == NULL) return false;
00219 line.fromXML(xmlNode);
00220
00221 xmlNode = node->getChildNode("color");
00222 if (xmlNode == NULL) return false;
00223 colorAverage.fromXML(xmlNode);
00224
00225 xmlNode = node->getChildNode("startpointcolor");
00226 if (xmlNode == NULL) return false;
00227 subNode = xmlNode->getChildNode("color");
00228 if (subNode == NULL) return false;
00229 colorStartPoint.fromXML(xmlNode);
00230
00231 xmlNode = node->getChildNode("endpointcolor");
00232 if (xmlNode == NULL) return false;
00233 subNode = xmlNode->getChildNode("color");
00234 if (subNode == NULL) return false;
00235 colorEndPoint.fromXML(xmlNode);
00236
00237 xmlNode = node->getChildNode("leftedgecolor");
00238 if (xmlNode == NULL) return false;
00239 subNode = xmlNode->getChildNode("color");
00240 if (subNode == NULL) return false;
00241 colorLeftEdge.fromXML(xmlNode);
00242
00243 xmlNode = node->getChildNode("rightedgecolor");
00244 if (xmlNode == NULL) return false;
00245 subNode = xmlNode->getChildNode("color");
00246 if (subNode == NULL) return false;
00247 colorRightEdge.fromXML(xmlNode);
00248
00249 return true;
00250 }
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269 ImagePolyLineFeature::ImagePolyLineFeature(JString creatorName, JTime t, double depth) {
00270 featureType = FEATURE_POLYLINE;
00271 creator = creatorName;
00272 frameTime = t;
00273 planeDepth = depth;
00274 }
00275
00276 ImagePolyLineFeature::~ImagePolyLineFeature() {
00277 }
00278
00279 ImagePolyLineFeature::ImagePolyLineFeature(JString xml) {
00280 if (!Object::fromXML(xml)) {
00281 }
00282 }
00283
00284 ImagePolyLineFeature::ImagePolyLineFeature(XMLNode* node) {
00285 if (!fromXML(node)) {
00286 }
00287 }
00288
00289 Object* ImagePolyLineFeature::clone() const {
00290 ImagePolyLineFeature* l = new ImagePolyLineFeature(creator, frameTime, planeDepth);
00291 *l = *this;
00292 return l;
00293 }
00294
00295
00296 PolyLine ImagePolyLineFeature::getPolyLine() {
00297 return polyLine;
00298 }
00299
00300 Color ImagePolyLineFeature::getColor() {
00301 return color;
00302 }
00303
00304 bool ImagePolyLineFeature::setPolyLine(PolyLine p) {
00305 polyLine = p;
00306 return true;
00307 }
00308
00309 bool ImagePolyLineFeature::setColor(Color c) {
00310 color = c;
00311 return true;
00312 }
00313
00314
00315
00316
00317 JString ImagePolyLineFeature::print() {
00318 return JString::format("PolyLineFeature: PolyLine:%s Color:%s", (char*) polyLine.print(), (char*) color.print());
00319 }
00320
00321 JString ImagePolyLineFeature::toXML() {
00322 return JString::format("<polylinefeature>\n%s%s</polylinefeature>", (char*) polyLine.toXML().indentXML(), (char*) color.toXML().indentXML());
00323 }
00324
00325 bool ImagePolyLineFeature::fromXML(XMLNode* node) {
00326 if (node == NULL) {
00327 return false;
00328 }
00329 if (!node->getTag().equalsIgnoreCase("polylinefeature"))
00330 return false;
00331
00332 XMLNode* xmlNode = node->getChildNode("polyline");
00333 if (xmlNode == NULL) return false;
00334 polyLine.fromXML(xmlNode);
00335 xmlNode = node->getChildNode("color");
00336 if (xmlNode == NULL) return false;
00337 color.fromXML(xmlNode);
00338
00339 return true;
00340 }
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352 }