Skip to content

Commit

Permalink
- Introduced base classes for annotation and annotationtool
Browse files Browse the repository at this point in the history
- Added statistics for annotation groups as well
- Added canClose options to WorkstationExtensions to enable them to prevent closing of ASAP
  • Loading branch information
GeertLitjens committed Feb 15, 2016
1 parent 246a69d commit f3f2211
Show file tree
Hide file tree
Showing 40 changed files with 711 additions and 700 deletions.
43 changes: 12 additions & 31 deletions annotation/Annotation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,10 @@ const char* Annotation::_typeStrings[5] = { "None", "Dot", "Polygon", "Spline",

Annotation::Annotation() :
_type(Annotation::NONE),
_coordinates(),
_name(""),
_color("#F4FA58")
_coordinates()
{
}

std::string Annotation::getColor() const {
return _color;
}

void Annotation::setColor(const std::string& color) {
_color = color;
}

std::string Annotation::getTypeAsString() const {
return _typeStrings[_type];
}
Expand All @@ -31,6 +21,7 @@ void Annotation::setTypeFromString(const std::string& type) {
_type = (Annotation::Type)i;
}
}
_modified = true;
}

float Annotation::getArea() const {
Expand All @@ -41,7 +32,7 @@ float Annotation::getArea() const {
area += (_coordinates[j].getX() + _coordinates[i].getX())*(_coordinates[j].getY() - _coordinates[i].getY());
j = i;
}
return area*.5;
return abs(area*.5);
}
else{
return 0.0;
Expand All @@ -55,11 +46,13 @@ unsigned int Annotation::getNumberOfPoints() const {
void Annotation::addCoordinate(const float& x, const float& y)
{
_coordinates.push_back(Point(x, y));
_modified = true;
}

void Annotation::addCoordinate(const Point& xy)
{
_coordinates.push_back(xy);
_modified = true;
}

void Annotation::insertCoordinate(const int& index, const Point& xy) {
Expand All @@ -69,10 +62,12 @@ void Annotation::insertCoordinate(const int& index, const Point& xy) {
else {
_coordinates.insert(_coordinates.begin() + index, xy);
}
_modified = true;
}

void Annotation::insertCoordinate(const int& index, const float& x, const float& y) {
this->insertCoordinate(index, Point(x, y));
_modified = true;
}

void Annotation::removeCoordinate(const int& index) {
Expand All @@ -82,6 +77,7 @@ void Annotation::removeCoordinate(const int& index) {
else {
_coordinates.erase(_coordinates.begin() + index);
}
_modified = true;
}

Point Annotation::getCoordinate(const int& index) const
Expand All @@ -102,41 +98,25 @@ std::vector<Point> Annotation::getCoordinates() const
void Annotation::setCoordinates(const std::vector<Point>& coordinates)
{
_coordinates = coordinates;
_modified = true;
}

void Annotation::clearCoordinates() {
_coordinates.clear();
_modified = true;
}

void Annotation::setType(const Annotation::Type& type)
{
_type = type;
_modified = true;
}

Annotation::Type Annotation::getType() const
{
return _type;
}

void Annotation::setName(const std::string& name)
{
_name = name;
}

std::string Annotation::getName() const
{
return _name;
};

void Annotation::setGroup(const std::shared_ptr<AnnotationGroup>& group) {
_group = group;
}

std::shared_ptr<AnnotationGroup> Annotation::getGroup() const {
std::shared_ptr<AnnotationGroup> grp = _group.lock();
return grp;
}

std::vector<Point> Annotation::getImageBoundingBox() const {
std::vector<Point> bbox;
Point topLeft(std::numeric_limits<float>::max(), std::numeric_limits<float>::max());
Expand Down Expand Up @@ -185,6 +165,7 @@ void Annotation::simplify(unsigned int nrPoints) {
float y = *it;
_coordinates.push_back(Point(x,y));
}
_modified = true;
}

Point Annotation::getCenter() {
Expand Down
15 changes: 2 additions & 13 deletions annotation/Annotation.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
#include <vector>
#include <map>
#include <memory>
#include "AnnotationBase.h"
#include "core/Point.h"
#include "config/pathology_config.h"

class AnnotationGroup;

class EXPORT_PATHOLOGYANNOTATION Annotation {
class EXPORT_PATHOLOGYANNOTATION Annotation : public AnnotationBase {
public:

enum Type {
Expand Down Expand Up @@ -39,15 +40,6 @@ class EXPORT_PATHOLOGYANNOTATION Annotation {
std::string getTypeAsString() const;
void setTypeFromString(const std::string& type);

void setName(const std::string& name);
std::string getName() const;

void setGroup(const std::shared_ptr<AnnotationGroup>& group);
std::shared_ptr<AnnotationGroup> getGroup() const;

std::string getColor() const;
void setColor(const std::string& color);

std::vector<Point> getImageBoundingBox() const;
std::vector<Point> getLocalBoundingBox();
Point getCenter();
Expand All @@ -60,9 +52,6 @@ class EXPORT_PATHOLOGYANNOTATION Annotation {
private:
Type _type;
std::vector<Point> _coordinates;
std::string _name;
std::weak_ptr<AnnotationGroup> _group;
static const char* _typeStrings[5];
std::string _color;
};
#endif
51 changes: 51 additions & 0 deletions annotation/AnnotationBase.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include "AnnotationBase.h"
#include "AnnotationGroup.h"
#include "psimpl.h"
#include <limits>

AnnotationBase::AnnotationBase() :
_name(""),
_color("#F4FA58"),
_modified(true)
{
}

AnnotationBase::~AnnotationBase() {
}

std::string AnnotationBase::getColor() const {
return _color;
}

void AnnotationBase::setColor(const std::string& color) {
_color = color;
}

void AnnotationBase::setName(const std::string& name)
{
_name = name;
}

std::string AnnotationBase::getName() const
{
return _name;
};

void AnnotationBase::setGroup(const std::shared_ptr<AnnotationGroup>& group) {
std::shared_ptr<AnnotationGroup> currentGroup = _group.lock();
if (!currentGroup || currentGroup != group) {
_group.reset();
if (currentGroup) {
currentGroup->removeMember(this->shared_from_this());
}
_group = group;
if (group) {
group->addMember(this->shared_from_this());
}
}
}

std::shared_ptr<AnnotationGroup> AnnotationBase::getGroup() const {
std::shared_ptr<AnnotationGroup> grp = _group.lock();
return grp;
}
44 changes: 44 additions & 0 deletions annotation/AnnotationBase.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#ifndef ANNOTATIONBASE_H
#define ANNOTATIONBASE_H

#include <string>
#include <vector>
#include <map>
#include <memory>
#include "core/Point.h"
#include "config/pathology_config.h"

class AnnotationGroup;

class EXPORT_PATHOLOGYANNOTATION AnnotationBase : public std::enable_shared_from_this<AnnotationBase> {
public:

AnnotationBase();
virtual ~AnnotationBase();

void setName(const std::string& name);
std::string getName() const;

void setGroup(const std::shared_ptr<AnnotationGroup>& group);
std::shared_ptr<AnnotationGroup> getGroup() const;

std::string getColor() const;
void setColor(const std::string& color);

virtual std::vector<Point> getImageBoundingBox() const = 0;
virtual std::vector<Point> getLocalBoundingBox() = 0;
virtual Point getCenter() = 0;

virtual float getArea() const = 0;
virtual unsigned int getNumberOfPoints() const = 0;

inline bool isModified() { return _modified; }
inline void resetModifiedStatus() { _modified = false; }

protected:
bool _modified;
std::string _name;
std::weak_ptr<AnnotationGroup> _group;
std::string _color;
};
#endif
Loading

0 comments on commit f3f2211

Please sign in to comment.