VPTissue Reference Manual
TissueSlicer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2016 Universiteit Antwerpen
3  *
4  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
5  * the European Commission - subsequent versions of the EUPL (the "Licence");
6  * You may not use this work except in compliance with the Licence.
7  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the Licence is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the Licence for the specific language governing
13  * permissions and limitations under the Licence.
14  */
20 #include "editor/PolygonUtils.h"
21 #include "slicer/SliceItem.h"
22 #include "bio/Cell.h"
23 #include "bio/Node.h"
24 #include "TissueSlicer.h"
25 
26 class QColor;
27 namespace SimPT_Shell { class EditControlLogic; }
28 
29 namespace SimPT_Editor {
30 
31 TissueSlicer::TissueSlicer(std::shared_ptr<EditControlLogic> tissue, QGraphicsScene* scene)
32  : m_tissue(tissue), m_scene(scene), m_cut(nullptr) {}
33 
35 {
36  delete m_cut;
37  for (auto slice : m_slices) {
38  delete slice;
39  }
40 }
41 
42 void TissueSlicer::StartCut(const QPointF& point)
43 {
44  m_cut = new QGraphicsLineItem(QLineF(point, point));
45  m_cut->setZValue(0.5);
46  m_cut->setPen(QPen(QBrush(QColor(0,0,255,255)), 0, Qt::DashLine));
47  m_scene->addItem(m_cut);
48 }
49 
51 {
52  QPolygonF boundaryPolygon;
53  for (auto node : m_tissue->GetMesh()->GetMesh()->GetBoundaryPolygon()->GetNodes()) {
54  boundaryPolygon.append(QPointF((*node)[0], (*node)[1]));
55  }
56 
57  for (auto polygon : PolygonUtils::SlicePolygon(boundaryPolygon, m_cut->line())) {
58  auto item = new SliceItem(polygon, m_cut->line(), m_tissue, m_scene);
59  item->setZValue(0.6);
60  connect(item, SIGNAL(Truncated()), this, SLOT(Finish()));
61  m_slices.push_back(item);
62  m_scene->addItem(item);
63  }
64 }
65 
66 bool TissueSlicer::MoveCut(const QPointF& point)
67 {
68  if (m_slices.size() == 0 && point != m_cut->line().p1()) {
69  // The cut-action hasn't ended yet and the given point is different from the first point.
70  m_cut->setLine(QLineF(m_cut->line().p1(), point));
71  return true;
72  }
73  else {
74  return false;
75  }
76 }
77 
79 {
80  return m_slices.size() > 0;
81 }
82 
83 void TissueSlicer::Finish()
84 {
85  m_scene->removeItem(m_cut);
86  for (auto slice : m_slices) {
87  m_scene->removeItem(slice);
88  }
89 
90  emit Finished();
91 }
92 
93 } // namespace
Represents a slice of a cell complex.
Definition: SliceItem.h:33
Interface for TissueSlicer.
Namespace for SimPT tissue editor package.
Definition: Cell.h:32
bool CutEnded() const
Checks whether the cut-action has ended.
Namespace for SimPT shell package.
Definition: Client.cpp:50
see the online Qt documentation
bool MoveCut(const QPointF &point)
This procedure is for dynamically moving the line in the canvas (the first point is fixed)...
static std::list< QPolygonF > SlicePolygon(const QPolygonF &polygon, QLineF cut)
Slice an open, simple and valid polygon in multiple polygons with a given line.
void EndCut()
End the cut procedure by putting a second point for the cut.
Interface for Cell.
Interface for Node.
void Finished()
Emitted when the slicing has finished.
virtual ~TissueSlicer()
Destructor.
void StartCut(const QPointF &point)
Start the cut procedure by putting a starting point for the cut.
TissueSlicer(std::shared_ptr< EditControlLogic > tissue, QGraphicsScene *scene)
Constructor.
Interface for PolygonUtils.
Interface for SliceItem.