ProcAnalyzer.cpp
Go to the documentation of this file.
1 #include <ros/console.h>
2 
4 
5 // for task sequence planning result
7 
11 
12 const static double FF_TRUNC_SCALE = 0.001;
13 
15 {
16 }
17 
19 {
20 }
21 
22 ProcAnalyzer::ProcAnalyzer(SeqAnalyzer *seqanalyzer, const char *path)
23 {
24  ptr_seqanalyzer_ = seqanalyzer;
25  path_ = path;
26  debug_ = false;
27 
28  ROS_INFO_STREAM("[ts planner] json output path: " << std::string(path_));
29 }
30 
32 {
34  DualGraph *ptr_dualgraph = ptr_seqanalyzer_->ptr_dualgraph_;
35 
36  QuadricCollision collision_checker = QuadricCollision(ptr_frame);
37 
38  std::vector<SingleTaskPlanningResult> planning_result;
40 
41  process_list_.clear();
42  process_list_.reserve(planning_result.size());
43 
44  support_ = 0;
45 
46  // extracting feasible angles
47  for (int i = 0; i < planning_result.size(); i++)
48  {
49  Process temp;
50  WF_edge* e = planning_result[i].e_;
51  temp.wireframe_id_ = e->ID();
52 
53  if (e->isPillar())
54  {
55  support_++;
56  }
57 
58  for(const auto& v : planning_result[i].eef_directions_)
59  {
60  temp.normal_.push_back(GeoV3(v[0], v[1], v[2]));
61  }
62 
63  process_list_.push_back(temp);
64  }
65 
66  // extracting start and end nodes
67  for (int i = 0; i < planning_result.size(); i++)
68  {
69  Process temp = process_list_[i];
70  WF_edge* e = planning_result[i].e_;
71 
72  int orig_j = e->ID();
73 
74  // st node index
75  int uj = ptr_frame->GetEndu(orig_j);
76  temp.start_ = ptr_frame->GetVert(uj)->Position();
77 
78  // end node index
79  int vj = ptr_frame->GetEndv(orig_j);
80  temp.end_ = ptr_frame->GetVert(vj)->Position();
81 
82  if (e->isPillar())
83  {
84  temp.fan_state_ = true;
85  }
86  else
87  {
88  // non-pillar element
89  // init
90  const bool start_node_exist = IfPointInVector(temp.start_);
91  const bool end_node_exist = IfPointInVector(temp.end_);
92 
93  // sanity check: at least one of the nodes should exist
94  assert(start_node_exist || end_node_exist);
95 
96 // // TODO: temp, to enable output for chosen layers' result
97 // if(!start_node_exist && !end_node_exist)
98 // {
99 // temp.fan_state_ = true;
100 // temp.start_ = start_node;
101 // temp.end_ = end_node;
102 // }
103 
104  // XOR - only one of them exist, "create type"
105  if (start_node_exist != end_node_exist)
106  {
107  temp.fan_state_ = true;
108  }
109  else
110  {
111  // AND - both of them exist, "connect type"
112  temp.fan_state_ = false;
113  }
114  }
115 
116  // pillar shouldn't have been printed yet
117  if (!IfPointInVector(temp.start_))
118  {
119  exist_point_.push_back(temp.start_);
120  }
121 
122  if (!IfPointInVector(temp.end_))
123  {
124  exist_point_.push_back(temp.end_);
125  }
126 
127  process_list_[i] = temp;
128  } // end loop for all elements (planning_result)
129 
130  return(WriteJson());
131 }
132 
134 {
135  using namespace rapidjson;
136 
137  std::string path = path_;
138  std::cout << path << std::endl;
139 
140  // document is the root of a json message
141  rapidjson::Document document;
142 
143  // define the document as an object rather than an array
144  document.SetObject();
145 
146  // must pass an allocator when the object may need to allocate memory
147  rapidjson::Document::AllocatorType& allocator = document.GetAllocator();
148 
149  Value model_object_container(rapidjson::kArrayType);
150  document.AddMember("element_number", process_list_.size(), allocator);
151  document.AddMember("support_number", support_, allocator);
152 
154 
155  rapidjson::Value bc_pt(rapidjson::kArrayType);
156  bc_pt.PushBack(Value().SetDouble(truncDigits(base_center_pt.x(), FF_TRUNC_SCALE)), allocator);
157  bc_pt.PushBack(Value().SetDouble(truncDigits(base_center_pt.y(), FF_TRUNC_SCALE)), allocator);
158  bc_pt.PushBack(Value().SetDouble(truncDigits(base_center_pt.z(), FF_TRUNC_SCALE)), allocator);
159  document.AddMember("base_center_pt", bc_pt, allocator);
160 
161  for (int i = 0; i < process_list_.size(); i++)
162  {
163  rapidjson::Value element_object_container(rapidjson::kObjectType);
164 
165  Process temp = process_list_[i];
166  element_object_container.AddMember("order_id", i, allocator);
167  element_object_container.AddMember("wireframe_id", temp.wireframe_id_, allocator);
168 
169  // start & end node coordination
170  point p_st = temp.start_;
171  rapidjson::Value st_pt(rapidjson::kArrayType);
172  st_pt.PushBack(Value().SetDouble(truncDigits(p_st.x(), FF_TRUNC_SCALE)), allocator);
173  st_pt.PushBack(Value().SetDouble(truncDigits(p_st.y(), FF_TRUNC_SCALE)), allocator);
174  st_pt.PushBack(Value().SetDouble(truncDigits(p_st.z(), FF_TRUNC_SCALE)), allocator);
175 
176  point p_end = temp.end_;
177  rapidjson::Value end_pt(rapidjson::kArrayType);
178  end_pt.PushBack(Value().SetDouble(truncDigits(p_end.x(), FF_TRUNC_SCALE)), allocator);
179  end_pt.PushBack(Value().SetDouble(truncDigits(p_end.y(), FF_TRUNC_SCALE)), allocator);
180  end_pt.PushBack(Value().SetDouble(truncDigits(p_end.z(), FF_TRUNC_SCALE)), allocator);
181 
182  element_object_container.AddMember("start_pt", st_pt, allocator);
183  element_object_container.AddMember("end_pt", end_pt, allocator);
184 
185  // element type
186  rapidjson::Value type_object(rapidjson::kObjectType);
187  if(i < support_)
188  {
189  element_object_container.AddMember("type", "support", allocator);
190  }
191  else
192  {
193  if(0 == temp.fan_state_)
194  {
195  element_object_container.AddMember("type", "connect", allocator);
196  }
197  else
198  {
199  element_object_container.AddMember("type", "create", allocator);
200  }
201  }
202 
203  // feasible orientations
204 // assert(temp.normal_.size() != 0);
205  if (temp.normal_.size() == 0)
206  {
207  cout << "Error: normal vector empty" << endl;
208  return false;
209  }
210  rapidjson::Value feasible_orients(rapidjson::kArrayType);
211  feasible_orients.Clear();
212 
213  if(i < support_)
214  {
215  rapidjson::Value feasible_orient(rapidjson::kArrayType);
216  feasible_orient.PushBack(Value().SetDouble(0.0), allocator);
217  feasible_orient.PushBack(Value().SetDouble(0.0), allocator);
218  feasible_orient.PushBack(Value().SetDouble(1.0), allocator);
219 
220  std::string vec_id = "f_orient" + std::to_string(0);
221  Value vec_id_key(vec_id.c_str(), allocator);
222 // feasible_orients.AddMember(vec_id_key, feasible_orient, allocator);
223  feasible_orients.PushBack(feasible_orient, allocator);
224  }
225  else
226  {
227  for (int j = 0; j < temp.normal_.size(); j++)
228  {
229  if (temp.normal_[j].getZ() < 0)
230  {
231  // filter out orientation point down
232  continue;
233  }
234  rapidjson::Value feasible_orient(rapidjson::kArrayType);
235  feasible_orient.PushBack(Value().SetDouble(truncDigits(temp.normal_[j].getX(), FF_TRUNC_SCALE)), allocator);
236  feasible_orient.PushBack(Value().SetDouble(truncDigits(temp.normal_[j].getY(), FF_TRUNC_SCALE)), allocator);
237  feasible_orient.PushBack(Value().SetDouble(truncDigits(temp.normal_[j].getZ(), FF_TRUNC_SCALE)), allocator);
238 
239  std::string vec_id = "f_orient" + std::to_string(j);
240  Value vec_id_key(vec_id.c_str(), allocator);
241 // feasible_orients.AddMember(vec_id_key, feasible_orient, allocator);
242  feasible_orients.PushBack(feasible_orient, allocator);
243  }
244  }
245 
246  element_object_container.AddMember(
247  "feasible_orientation", feasible_orients, allocator);
248 
249  std::string id = "element" + std::to_string(i);
250  Value id_key(id.c_str(), allocator);
251 
252  model_object_container.PushBack(element_object_container, allocator);
253 // document.AddMember(id_key, element_object_container, allocator);
254  }
255 
256  document.AddMember("sequenced_elements", model_object_container, allocator);
257 
258  // output file to path
259  std::string json_path = path;
260  FILE *js_file = fopen(json_path.c_str(), "w+");
261  if(NULL == js_file)
262  {
263  std::cout << "ERROR: invalid output file path!!!" << endl;
264  return false;
265  }
266 
267  char writeBuffer[65536];
268  FileWriteStream os(js_file, writeBuffer, sizeof(writeBuffer));
269 
270  PrettyWriter<FileWriteStream> p_writer(os);
271  document.Accept(p_writer);
272 
273  std::fclose(js_file);
274  std::cout << "path file saved successfully!" << std::endl;
275  return true;
276 }
277 
279 {
280  for (int i = 0; i <exist_point_.size(); i++)
281  {
282  if ((exist_point_[i] - p).length() < GEO_EPS)
283  return true;
284  }
285  return false;
286 }
#define GEO_EPS
Definition: GCommon.h:62
GLsizei const GLchar *const * path
vector< point > exist_point_
Definition: ProcAnalyzer.h:59
reference x()
Definition: Vec.h:194
bool isPillar() const
Definition: WireFrame.h:125
WireFrame * ptr_frame_
Definition: SeqAnalyzer.h:132
Vec3f GetBaseCenterPos() const
Definition: WireFrame.h:249
vector< Process > process_list_
Definition: ProcAnalyzer.h:62
void OutputTaskSequencePlanningResult(std::vector< SingleTaskPlanningResult > &planning_result)
int ID() const
Definition: WireFrame.h:123
GLuint writeBuffer
double truncDigits(double v, double scale)
Definition: ProcAnalyzer.h:53
static const double FF_TRUNC_SCALE
bool ProcPrint()
reference y()
Definition: Vec.h:203
DualGraph * ptr_dualgraph_
Definition: SeqAnalyzer.h:133
bool IfPointInVector(point p)
SeqAnalyzer * ptr_seqanalyzer_
Definition: ProcAnalyzer.h:56
int GetEndv(int i) const
Definition: WireFrame.h:245
point start_
Definition: ProcAnalyzer.h:34
const GLdouble * v
bool fan_state_
Definition: ProcAnalyzer.h:32
#define ROS_INFO_STREAM(args)
point end_
Definition: ProcAnalyzer.h:35
std::vector< GeoV3 > normal_
Definition: ProcAnalyzer.h:36
int GetEndu(int i) const
Definition: WireFrame.h:244
const char * path_
Definition: ProcAnalyzer.h:57
reference z()
Definition: Vec.h:212
GLfloat GLfloat p
int wireframe_id_
Definition: ProcAnalyzer.h:33
Geometry::Vector3d GeoV3
Definition: Polyface.h:51
point Position() const
Definition: WireFrame.h:78
WF_vert * GetVert(int u)
Definition: WireFrame.h:237


choreo_task_sequence_planner
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:03:14