1 #ifndef OPENSIM_MARKER_DATA_H_ 2 #define OPENSIM_MARKER_DATA_H_ 3 /* -------------------------------------------------------------------------- * 4 * OpenSim: MarkerData.h * 5 * -------------------------------------------------------------------------- * 6 * The OpenSim API is a toolkit for musculoskeletal modeling and simulation. * 7 * See http://opensim.stanford.edu and the NOTICE file for more information. * 8 * OpenSim is developed at Stanford University and supported by the US * 9 * National Institutes of Health (U54 GM072970, R24 HD065690) and by DARPA * 10 * through the Warrior Web program. * 11 * * 12 * Copyright (c) 2005-2017 Stanford University and the Authors * 13 * Author(s): Peter Loan * 14 * * 15 * Licensed under the Apache License, Version 2.0 (the "License"); you may * 16 * not use this file except in compliance with the License. You may obtain a * 17 * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. * 18 * * 19 * Unless required by applicable law or agreed to in writing, software * 20 * distributed under the License is distributed on an "AS IS" BASIS, * 21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 22 * See the License for the specific language governing permissions and * 23 * limitations under the License. * 24 * -------------------------------------------------------------------------- */ 25 26 27 // INCLUDE 28 #include <iostream> 29 #include <string> 30 #include "Array.h" 31 #include "ArrayPtrs.h" 32 #include "MarkerFrame.h" 33 #include "Object.h" 34 #include "Units.h" 35 36 namespace OpenSim { 37 38 class Storage; 39 40 //============================================================================= 41 //============================================================================= 42 /** 43 * A class implementing a sequence of marker frames from a TRC/TRB file. 44 * 45 * @author Peter Loan 46 * @version 1.0 47 */ 48 class OSIMCOMMON_API MarkerData : public Object { 49 OpenSim_DECLARE_CONCRETE_OBJECT(MarkerData, Object); 50 51 //============================================================================= 52 // DATA 53 //============================================================================= 54 private: 55 int _numFrames; 56 int _numMarkers; 57 int _firstFrameNumber; 58 double _dataRate; 59 double _cameraRate; 60 double _originalDataRate; 61 int _originalStartFrame; 62 int _originalNumFrames; 63 std::string _fileName; 64 Units _units; 65 Array<std::string> _markerNames; 66 ArrayPtrs<MarkerFrame> _frames; 67 68 //============================================================================= 69 // METHODS 70 //============================================================================= 71 //-------------------------------------------------------------------------- 72 // CONSTRUCTION 73 //-------------------------------------------------------------------------- 74 public: 75 MarkerData(); 76 explicit MarkerData(const std::string& aFileName) SWIG_DECLARE_EXCEPTION; 77 virtual ~MarkerData(); 78 79 void findFrameRange(double aStartTime, double aEndTime, int& rStartFrame, int& rEndFrame) const; 80 void averageFrames(double aThreshold = -1.0, double aStartTime = -SimTK::Infinity, double aEndTime = SimTK::Infinity); getFileName()81 const std::string& getFileName() const { return _fileName; } 82 void makeRdStorage(Storage& rStorage); 83 const MarkerFrame& getFrame(int aIndex) const; 84 int getMarkerIndex(const std::string& aName) const; getUnits()85 const Units& getUnits() const { return _units; } 86 void convertToUnits(const Units& aUnits); getMarkerNames()87 const Array<std::string>& getMarkerNames() const { return _markerNames; } getNumMarkers()88 int getNumMarkers() const { return _numMarkers; } getNumFrames()89 int getNumFrames() const { return _numFrames; } 90 double getStartFrameTime() const; 91 double getLastFrameTime() const; getDataRate()92 double getDataRate() const { return _dataRate; } getCameraRate()93 double getCameraRate() const { return _cameraRate; } 94 95 private: 96 void readTRCFile(const std::string& aFileName, MarkerData& aSMD); 97 void readTRCFileHeader(std::ifstream &in, const std::string& aFileName, MarkerData& aSMD); 98 void readTRBFile(const std::string& aFileName, MarkerData& aSMD); 99 void readStoFile(const std::string& aFileName); 100 void buildMarkerMap(const Storage& storageToReadFrom, std::map<int, std::string>& markerNames); 101 102 //============================================================================= 103 }; // END of class MarkerData 104 //============================================================================= 105 //============================================================================= 106 107 } // end of namespace OpenSim 108 109 #endif // OPENSIM_MARKER_DATA_H_ 110 111 112