contrib/brl/bbas/bugl/bugl_curve_3d.cxx
Go to the documentation of this file.
00001 #include "bugl_curve_3d.h"
00002 #include <bugl/bugl_normal_point_3d_sptr.h>
00003 #include <vcl_cassert.h>
00004 
00005 bugl_normal_point_3d_sptr bugl_curve_3d::get_point(unsigned int index) const
00006 {
00007   assert(index < data_.size());
00008   return data_[index][num_neighbors_];
00009 }
00010 
00011 vcl_vector<bugl_normal_point_3d_sptr> bugl_curve_3d::get_neighbors(unsigned int index) const
00012 {
00013   assert(index < data_.size());
00014   return data_[index];
00015 }
00016 
00017 bugl_normal_point_3d_sptr bugl_curve_3d::get_neighbor(unsigned int self, int offset) const
00018 {
00019   assert(offset > -int(num_neighbors_) && offset < int(num_neighbors_));
00020   return data_[self][num_neighbors_ + offset];
00021 }
00022 
00023 void bugl_curve_3d::add_curve(vcl_vector<bugl_normal_point_3d_sptr > & pts)
00024 {
00025   unsigned int size = pts.size();
00026   assert(size > 2*num_neighbors_ + 1);
00027 
00028   int prev_total = data_.size();
00029 
00030   vcl_vector<bugl_normal_point_3d_sptr> seg(2*num_neighbors_+1);
00031   for (unsigned int i=0; i<size; i++){
00032     seg[num_neighbors_] = pts[i]; // assign the middle point
00033     for (unsigned int j=1; j<=num_neighbors_; j++){
00034       // assign the left neighbors
00035       if (j > i)
00036         seg[num_neighbors_-j] = 0;
00037       else
00038         seg[num_neighbors_-j] = pts[i-j];
00039 
00040       // assign the right neighbors
00041       if (i+j < size)
00042         seg[num_neighbors_ + j] = pts[i+j];
00043       else
00044         seg[num_neighbors_ + j] = 0;
00045     }//end neighbors
00046 
00047     data_.push_back(seg);
00048   }//end of all the points
00049 
00050   index_.push_back(prev_total);
00051 }
00052 
00053 unsigned int bugl_curve_3d::get_fragment_size(unsigned int i) const
00054 {
00055   if (i+1<index_.size())
00056     return index_[i+1] - index_[i];
00057   else 
00058     return data_.size() - index_[i];
00059 }