#include <Position.h>
Inheritance diagram for gadget::Position:


Public Types | |
| typedef gadget::SampleBuffer< PositionData > | SampleBuffer_t |
Public Methods | |
| Position () | |
| Constructor. More... | |
| virtual | ~Position () |
| Destructor. More... | |
| virtual bool | config (jccl::ConfigElementPtr e) |
| PositionData | getPositionData (int devNum=0) |
| Get Positional data. More... | |
| void | addPositionSample (std::vector< PositionData > posSample) |
| Helper method to add a sample to the sample buffers. More... | |
| void | swapPositionBuffers () |
| Swap the position data buffers. More... | |
| virtual std::string | getBaseType () |
| virtual vpr::ReturnStatus | writeObject (vpr::ObjectWriter *writer) |
| virtual vpr::ReturnStatus | readObject (vpr::ObjectReader *reader) |
| const SampleBuffer_t::buffer_t & | getPositionDataBuffer () |
Protected Methods | |
| Position (const gadget::Position &d) | |
| void | operator= (const gadget::Position &d) |
Protected Attributes | |
| PositionData | mDefaultValue |
| Default positional value to return. More... | |
Position is the base class that digital devices must derive from. Position inherits from Input, so it has pure virtual function constraints from Input in the following functions: StartSampling,StopSampling,Sample, and UpdateData.
Position objects have the ability to convert from the tracker's coord system to the Juggler coordinate system.
Position adds one new pure virtual function, getPositionData() for retreiving the positional data, similar to the addition for gadget:;Analog and gadget:;Digital.
Definition at line 74 of file Position.h.
|
|
Definition at line 77 of file Position.h. |
|
|
Constructor.
Definition at line 56 of file Position.cpp.
00057 {;}
|
|
|
Destructor.
Definition at line 59 of file Position.cpp.
00060 {;}
|
|
|
Definition at line 149 of file Position.h.
00149 : vpr::SerializableObject() {;}
|
|
|
Reimplemented in gadget::SimPosition. Definition at line 64 of file Position.cpp.
00065 {
00066 // --- Configure filters --- //
00067 unsigned num_filters = e->getNum("position_filters");
00068
00069 vprDEBUG_OutputGuard(vprDBG_ALL, vprDBG_VERB_LVL,
00070 std::string("Position::config: ") + e->getName() +
00071 std::string(":") + e->getID() +
00072 std::string("\n"),
00073 std::string("Position::config: done.\n") );
00074
00075 vprDEBUG(vprDBG_ALL, vprDBG_VERB_LVL)
00076 << "Num filters: " << num_filters << std::endl << vprDEBUG_FLUSH;
00077
00078 jccl::ConfigElementPtr cur_filter;
00079 PositionFilter* new_filter = NULL;
00080
00081 for(unsigned i=0;i<num_filters;++i)
00082 {
00083 cur_filter = e->getProperty<jccl::ConfigElementPtr>("position_filters",i);
00084 vprASSERT(cur_filter.get() != NULL);
00085
00086 std::string filter_id = cur_filter->getID();
00087 vprDEBUG( vprDBG_ALL, vprDBG_VERB_LVL)
00088 << " Filter [" << i << "]: Type:" << filter_id
00089 << std::endl << vprDEBUG_FLUSH;
00090
00091 new_filter = PositionFilterFactory::instance()->createObject(filter_id);
00092 if(new_filter != NULL)
00093 {
00094 new_filter->config(cur_filter);
00095 mPositionFilters.push_back(new_filter);
00096 }
00097 else
00098 {
00099 vprDEBUG(vprDBG_ALL, vprDBG_VERB_LVL)
00100 << " NULL Filter!!!" << std::endl << vprDEBUG_FLUSH;
00101 }
00102 }
00103
00104 return true;
00105 }
|
|
|
Get Positional data.
Definition at line 90 of file Position.h.
00091 {
00092 SampleBuffer_t::buffer_t& stable_buffer = mPosSamples.stableBuffer();
00093
00094 if ((!stable_buffer.empty()) &&
00095 (stable_buffer.back().size() > (unsigned)devNum)) // If Have entry && devNum in range
00096 {
00097 return stable_buffer.back()[devNum];
00098 }
00099 else // No data or request out of range, return default value
00100 {
00101 if(stable_buffer.empty())
00102 {
00103 vprDEBUG(vprDBG_ALL, vprDBG_WARNING_LVL) << "Warning: Position::getPositionData: Stable buffer is empty. If this is not the first read, then this is a problem.\n" << vprDEBUG_FLUSH;
00104 }
00105 else
00106 {
00107 vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL) << "Warning: Position::getPositionData: Requested devNum is not in the range available. May have configuration error\n" << vprDEBUG_FLUSH;
00108 }
00109
00110 return mDefaultValue;
00111 }
00112 }
|
|
|
Helper method to add a sample to the sample buffers. This MUST be called by all positional devices to add a new sample. The data samples passed in will then be modified by any local filters. The tracker transformations will occur in those filters, so the data does not need to be xformed before bing passed in.
Definition at line 224 of file Position.cpp. References gadget::SampleBuffer< PositionData >::addSample, gadget::SampleBuffer< PositionData >::lock, and gadget::SampleBuffer< PositionData >::unlock. Referenced by gadget::SimSetablePosition::setData, gadget::SimRelativePosition::updateData, and gadget::SimPosition::updateData.
00225 {
00226 // Apply all the positional filters
00227 for(std::vector<PositionFilter*>::iterator i = mPositionFilters.begin(); i != mPositionFilters.end(); ++i)
00228 {
00229 (*i)->apply(posSample);
00230 }
00231
00232 // Locks and then swaps the indices.
00233 mPosSamples.lock();
00234 mPosSamples.addSample(posSample);
00235 mPosSamples.unlock();
00236 }
|
|
|
Swap the position data buffers.
Definition at line 127 of file Position.h. Referenced by readObject, gadget::SimSetablePosition::setData, gadget::SimRelativePosition::updateData, and gadget::SimPosition::updateData.
00128 {
00129 mPosSamples.swapBuffers();
00130 }
|
|
|
Reimplemented in gadget::InputMixer< Input, Position >. Definition at line 132 of file Position.h.
00133 {
00134 return std::string("Position");
00135 }
|
|
|
Reimplemented in gadget::InputMixer< Input, Position >. Definition at line 107 of file Position.cpp. References gadget::SampleBuffer< PositionData >::lock, gadget::MSG_DATA_POS, gadget::SampleBuffer< PositionData >::stableBuffer, and gadget::SampleBuffer< PositionData >::unlock.
00108 {
00109 SampleBuffer_t::buffer_t& stable_buffer = mPosSamples.stableBuffer();
00110
00111 writer->beginTag(Position::getBaseType());
00112 writer->beginAttribute(gadget::tokens::DataTypeAttrib);
00113 writer->writeUint16(MSG_DATA_POS); // Write out the data type so that we can assert if reading in wrong place
00114 writer->endAttribute();
00115
00116 writer->beginAttribute(gadget::tokens::SampleBufferLenAttrib);
00117 writer->writeUint16(stable_buffer.size()); // Write the size of the stable buffer
00118 writer->endAttribute();
00119
00120 if ( !stable_buffer.empty() )
00121 {
00122 mPosSamples.lock();
00123 for ( unsigned j=0;j<stable_buffer.size();j++ )
00124 {
00125 writer->beginTag(gadget::tokens::BufferSampleTag);
00126 writer->beginAttribute(gadget::tokens::BufferSampleLenAttrib);
00127 writer->writeUint16(stable_buffer[j].size()); // Number of pos values for this entry
00128 writer->endAttribute();
00129
00130 for ( unsigned i=0;i<stable_buffer[j].size();i++ ) // For each pos value
00131 {
00132 gmtl::Matrix44f* PosMatrix = &(stable_buffer[j][i].mPosData);
00133 const float* pos_data = PosMatrix->getData();
00134
00135 writer->beginTag(gadget::tokens::PosValue);
00136 for ( int n=0;n<16;n++ )
00137 { writer->writeFloat(pos_data[n]); }
00138
00139 writer->beginAttribute(gadget::tokens::TimeStamp);
00140 writer->writeUint64(stable_buffer[j][i].getTime().usec()); // Write Time Stamp vpr::Uint64
00141 writer->endAttribute();
00142 writer->endTag();
00143 }
00144 writer->endTag();
00145 }
00146 mPosSamples.unlock();
00147 }
00148 else // No data or request out of range, return default value
00149 {
00150 vprDEBUG(vprDBG_ALL, vprDBG_WARNING_LVL) << "Warning: Position::writeObject: Stable buffer is empty. If this is not the first write, then this is a problem.\n" << vprDEBUG_FLUSH;
00151 }
00152 writer->endTag();
00153
00154 return vpr::ReturnStatus::Succeed;
00155 }
|
|
|
Reimplemented in gadget::InputMixer< Input, Position >. Definition at line 158 of file Position.cpp. References gadget::SampleBuffer< PositionData >::addSample, gadget::SampleBuffer< PositionData >::lock, gadget::MSG_DATA_POS, swapPositionBuffers, and gadget::SampleBuffer< PositionData >::unlock.
00159 {
00160 vprASSERT(reader->attribExists("rim.timestamp.delta"));
00161 vpr::Uint64 delta = reader->getAttrib<vpr::Uint64>("rim.timestamp.delta");
00162
00163 reader->beginTag(Position::getBaseType());
00164 reader->beginAttribute(gadget::tokens::DataTypeAttrib);
00165 vpr::Uint16 temp = reader->readUint16();
00166 reader->endAttribute();
00167
00168 // XXX: Should there be error checking for the case when vprASSERT() is
00169 // compiled out? -PH 8/21/2003
00170 vprASSERT(temp==MSG_DATA_POS && "[Remote Input Manager]Not Positional Data");
00171 boost::ignore_unused_variable_warning(temp);
00172
00173 std::vector<PositionData> dataSample;
00174
00175 unsigned numPosDatas;
00176 vpr::Uint64 timeStamp;
00177 PositionData temp_pos_data;
00178 float pos_data[16];
00179 gmtl::Matrix44f PosMatrix;
00180
00181 reader->beginAttribute(gadget::tokens::SampleBufferLenAttrib);
00182 unsigned numVectors = reader->readUint16();
00183 reader->endAttribute();
00184
00185 mPosSamples.lock();
00186 for ( unsigned i=0;i<numVectors;i++ )
00187 {
00188 reader->beginTag(gadget::tokens::BufferSampleTag);
00189 reader->beginAttribute(gadget::tokens::BufferSampleLenAttrib);
00190 numPosDatas = reader->readUint16();
00191 reader->endAttribute();
00192
00193 dataSample.clear();
00194
00195 for ( unsigned j=0;j<numPosDatas;j++ )
00196 {
00197 reader->beginTag(gadget::tokens::PosValue);
00198 //NOTE: This uses the value 16 because we are using a 4x4 matrix
00199 //for the position dataAt this point there is not a good
00200 //way to get the row and column value of any given size matrix
00201 for ( unsigned n=0;n<16;n++ )
00202 { pos_data[n] = reader->readFloat(); }
00203 PosMatrix.set(pos_data);
00204
00205 reader->beginAttribute(gadget::tokens::TimeStamp);
00206 timeStamp = reader->readUint64();
00207 reader->endAttribute();
00208 reader->endTag();
00209
00210 temp_pos_data.setPosition(PosMatrix);
00211 temp_pos_data.setTime(vpr::Interval(timeStamp + delta,vpr::Interval::Usec));
00212 dataSample.push_back(temp_pos_data);
00213 }
00214 mPosSamples.addSample(dataSample);
00215 reader->endTag();
00216 }
00217 mPosSamples.unlock();
00218 swapPositionBuffers();
00219 reader->endTag();
00220
00221 return(vpr::ReturnStatus::Succeed);
00222 }
|
|
|
Definition at line 140 of file Position.h.
00141 {
00142 return mPosSamples.stableBuffer();
00143 }
|
|
|
Definition at line 150 of file Position.h.
00150 {;}
|
|
|
Default positional value to return.
Definition at line 146 of file Position.h. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002