OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
PhotoBlock.cpp
Go to the documentation of this file.
1 //**************************************************************************************************
2 //
3 // OSSIM Open Source Geospatial Data Processing Library
4 // See top level LICENSE.txt file for license information
5 //
6 //**************************************************************************************************
7 
8 #include <ossim/reg/PhotoBlock.h>
10 
11 namespace ossim
12 {
14 {
15 }
16 
17 PhotoBlock::PhotoBlock(const Json::Value& pb_json_node)
18 {
19  loadJSON(pb_json_node);
20 }
21 
23 : m_imageList (copyThis.m_imageList),
24  m_tiePointList (copyThis.m_tiePointList)
25 {
26  *this = copyThis;
27 }
28 
30 {
31  m_imageList.clear();
32  m_tiePointList.clear();
33 }
34 
36 {
37  m_imageList = copythis.m_imageList;
38  m_tiePointList = copythis.m_tiePointList;
39  m_gcpList = copythis.m_gcpList;
40  return *this;
41 }
42 
43 // TODO: Add of individual components not available until proper management of the JCM can be
44 // provided
45 unsigned int PhotoBlock::addImage(shared_ptr<Image> image)
46 {
47  unsigned int last_idx = m_imageList.size();
48  m_imageList.push_back(image);
49  return last_idx;
50 }
51 
52 unsigned int PhotoBlock::addGroundPoint(shared_ptr<GroundControlPoint> gcp)
53 {
54  unsigned int last_idx = m_gcpList.size();
55  m_gcpList.push_back(gcp);
56  return last_idx;
57 }
58 
59 unsigned int PhotoBlock::addTiePoint(shared_ptr<TiePoint> tiepoint)
60 {
61  unsigned int index = m_tiePointList.size();
62  m_tiePointList.push_back(tiepoint);
63  return index;
64 }
65 
67 {
68  for (size_t i=0; i<tiepointList.size(); ++i)
69  {
70  addTiePoint(tiepointList[i]);
71  }
72 }
73 
74 shared_ptr<Image> PhotoBlock::getImage(const std::string& imageId)
75 {
76  std::shared_ptr<Image> result;
77  for (size_t i=0; i<m_imageList.size(); ++i)
78  {
79  if (m_imageList[i]->getImageId() == imageId)
80  {
81  result = m_imageList[i];
82  break;
83  }
84  }
85  return result;
86 }
87 
88 shared_ptr<GroundControlPoint> PhotoBlock::getGroundPoint(const std::string& gcpId)
89 {
90  std::shared_ptr<GroundControlPoint> result;
91  for (size_t i=0; i<m_gcpList.size(); ++i)
92  {
93  if (m_gcpList[i]->getId() == gcpId)
94  {
95  result = m_gcpList[i];
96  break;
97  }
98  }
99  return result;
100 }
101 
102 shared_ptr<TiePoint> PhotoBlock::getTiePoint(unsigned int tpId)
103 {
104  std::shared_ptr<TiePoint> result;
105  for (size_t i=0; i<m_tiePointList.size(); ++i)
106  {
107  if (m_tiePointList[i]->getTiePointId() == tpId)
108  {
109  result = m_tiePointList[i];
110  break;
111  }
112  }
113  return result;
114 }
115 
116 void PhotoBlock::loadJSON(const Json::Value& pb_json_node)
117 {
118  // Always do images first, as tiepoints will be using the image list to correct image ID:
119  if (pb_json_node.isMember("images"))
120  {
121  const Json::Value& listJson = pb_json_node["images"];
122  unsigned int count = listJson.size();
123  for (unsigned int i=0; i<count; ++i)
124  {
125  const Json::Value& jsonItem = listJson[i];
126  shared_ptr<Image> item (new Image(jsonItem));
127  m_imageList.push_back(item);
128  }
129  }
130 
131  if (pb_json_node.isMember("groundPoints"))
132  {
133  const Json::Value& listJson = pb_json_node["groundPoints"];
134  unsigned int count = listJson.size();
135  for (unsigned int i=0; i<count; ++i)
136  {
137  const Json::Value& jsonItem = listJson[i];
138  shared_ptr<GroundControlPoint> item (new GroundControlPoint(jsonItem));
139  m_gcpList.push_back(item);
140  }
141  }
142 
143  if (pb_json_node.isMember("tiePoints"))
144  {
145  const Json::Value& listJson = pb_json_node["tiePoints"];
146  unsigned int count = listJson.size();
147  for (unsigned int i=0; i<count; ++i)
148  {
149  const Json::Value& jsonItem = listJson[i];
150  shared_ptr<TiePoint> item (new TiePoint(jsonItem));
151  m_tiePointList.push_back(item);
152  }
153  }
154 }
155 
156 void PhotoBlock::saveJSON(Json::Value& pbJSON) const
157 {
158  Json::Value imageListJson (Json::arrayValue);
159  unsigned int count = m_imageList.size();
160  for (unsigned int i=0; i<count; ++i)
161  {
162  m_imageList[i]->saveJSON(imageListJson[i]);
163  }
164  pbJSON["images"] = imageListJson;
165 
166  Json::Value gcpListJson (Json::arrayValue);
167  count = m_gcpList.size();
168  for (unsigned int i=0; i<count; ++i)
169  {
170  m_gcpList[i]->saveJSON(gcpListJson[i]);
171  }
172  pbJSON["groundPoints"] = gcpListJson;
173 
174  Json::Value tpListJson (Json::arrayValue);
175  count = m_tiePointList.size();
176  for (unsigned int i=0; i<count; ++i)
177  {
178  m_tiePointList[i]->saveJSON(tpListJson[i]);
179  }
180  pbJSON["tiePoints"] = tpListJson;
181 }
182 
183 } // end namespace
std::vector< std::shared_ptr< TiePoint > > m_tiePointList
Definition: PhotoBlock.h:93
std::vector< std::shared_ptr< Image > > m_imageList
Definition: PhotoBlock.h:92
This code was derived from https://gist.github.com/mshockwave.
Definition: Barrier.h:8
PhotoBlock()
Initialize the photoblock from a prior saved session.
Definition: PhotoBlock.cpp:13
PhotoBlock & operator=(const PhotoBlock &copythis)
Definition: PhotoBlock.cpp:35
Class for representing MSP PhotoBlock.
Definition: PhotoBlock.h:25
void addTiePoints(TiePointList &tiepointList)
Adds the list of tiepoints to the PB.
Definition: PhotoBlock.cpp:66
Class for representing a ground control point.
std::vector< std::shared_ptr< TiePoint > > TiePointList
Definition: TiePoint.h:21
Class representing an Image as used by ossim-msp services.
Definition: Image.h:27
unsigned int addTiePoint(std::shared_ptr< TiePoint > tiepoint)
Adds the tiepoint to the PB.
Definition: PhotoBlock.cpp:59
virtual void loadJSON(const Json::Value &json)
Definition: PhotoBlock.cpp:116
std::shared_ptr< TiePoint > getTiePoint(unsigned int tpId)
Definition: PhotoBlock.cpp:102
unsigned int addGroundPoint(std::shared_ptr< GroundControlPoint > groundPoint)
Adds the image to the photoblock at last position.
Definition: PhotoBlock.cpp:52
virtual void saveJSON(Json::Value &json) const
Definition: PhotoBlock.cpp:156
unsigned int addImage(std::shared_ptr< Image > image)
Adds the image to the photoblock at last position.
Definition: PhotoBlock.cpp:45
Class for representing a single tiepoint on two or more images.
Definition: TiePoint.h:28
std::vector< std::shared_ptr< GroundControlPoint > > m_gcpList
Definition: PhotoBlock.h:94
std::shared_ptr< GroundControlPoint > getGroundPoint(const std::string &gpId)
Definition: PhotoBlock.cpp:88
std::shared_ptr< Image > getImage(const std::string &imageId)
Definition: PhotoBlock.cpp:74