diff --git a/include/openspace/rendering/planets/renderableplanetprojection.h b/include/openspace/rendering/planets/renderableplanetprojection.h index a6a2c57fa0..016f6ee3cc 100644 --- a/include/openspace/rendering/planets/renderableplanetprojection.h +++ b/include/openspace/rendering/planets/renderableplanetprojection.h @@ -29,6 +29,12 @@ // open space includes #include #include +#include + +#include +#include +#include + #include #include @@ -71,6 +77,8 @@ protected: private: void imageProjectGPU(); + std::map _fileTranslation; + properties::StringProperty _colorTexturePath; properties::StringProperty _projectionTexturePath; properties::TriggerProperty _imageTrigger; @@ -87,12 +95,19 @@ private: glm::mat4 _transform; glm::mat4 _projectorMatrix; + //sequenceloading + std::string _sequenceSource; + std::string _sequenceType; + bool _foundSequence; + // spice std::string _instrumentID; std::string _projectorID; std::string _projecteeID; std::string _aberration; std::vector _potentialTargets; // @TODO copy-n-paste from renderablefov + + float _fovy; float _aspectRatio; float _nearPlane; @@ -110,7 +125,6 @@ private: std::vector> _imageTimes; int _sequenceID; - std::string _target; std::string _defaultProjImage; std::string _next; diff --git a/include/openspace/util/camerainstrument.h b/include/openspace/util/camerainstrument.h new file mode 100644 index 0000000000..6236f83896 --- /dev/null +++ b/include/openspace/util/camerainstrument.h @@ -0,0 +1,46 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2015 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#ifndef __CAMERAINSTRUMENT_H__ +#define __CAMERAINSTRUMENT_H__ + +#include + +#include + +namespace openspace { + +class CameraInstrument : public Payload { +public: + CameraInstrument(const ghoul::Dictionary& dictionary); + virtual std::string getType(); + virtual std::vector getSpiceIDs(); +private: + std::string _type; + std::vector _spiceIDs; +}; + +} // namespace openspace + +#endif // __CAMERAINSTRUMENT_H__ diff --git a/include/openspace/util/hongkangparser.h b/include/openspace/util/hongkangparser.h new file mode 100644 index 0000000000..63d52ae535 --- /dev/null +++ b/include/openspace/util/hongkangparser.h @@ -0,0 +1,85 @@ +/***************************************************************************************** +* * +* OpenSpace * +* * +* Copyright (c) 2014-2015 * +* * +* Permission is hereby granted, free of charge, to any person obtaining a copy of this * +* software and associated documentation files (the "Software"), to deal in the Software * +* without restriction, including without limitation the rights to use, copy, modify, * +* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * +* permit persons to whom the Software is furnished to do so, subject to the following * +* conditions: * +* * +* The above copyright notice and this permission notice shall be included in all copies * +* or substantial portions of the Software. * +* * +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * +* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * +* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * +* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * +* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * +* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * +****************************************************************************************/ + + +#ifndef __HONGKANGPARSER_H__ +#define __HONGKANGPARSER_H__ +#include +#include + + +#include +#include +#include + +namespace openspace { + + class HongKangParser : public SequenceParser{ + public: + HongKangParser(); + HongKangParser(const std::string& fileName, + std::string spacecraft, + std::map acronymDictionary, + std::vector potentialTargets); + virtual void create(); + virtual std::map getSubsetMap(); + virtual std::vector> getIstrumentTimes(); + virtual std::vector> getTargetTimes(); + + // temporary need to figure this out + std::map getAcronymDictionary(){ return _fileTranslation; }; + + private: + double getMetFromET(double et); + double getETfromMet(std::string timestr); + double getETfromMet(double met); + + void createImage(Image& image, + double startTime, + double stopTime, + std::vector instr, + std::string targ, + std::string pot); + + bool augmentWithSpice(Image& image, + std::string spacecraft, + std::vector payload, + std::vector potentialTargets); + + + std::map _subsetMap; + std::vector> _instrumentTimes; + std::vector> _targetTimes; + + std::string _defaultCaptureImage; + double _metRef = 299180517; + + std::string _fileName; + std::string _spacecraft; + std::map _fileTranslation; + std::vector _potentialTargets; + }; + +} +#endif //__HONGKANGPARSER_H__ \ No newline at end of file diff --git a/include/openspace/util/imagesequencer.h b/include/openspace/util/imagesequencer.h index a557a45205..8dad22159c 100644 --- a/include/openspace/util/imagesequencer.h +++ b/include/openspace/util/imagesequencer.h @@ -99,11 +99,10 @@ public: */ bool parsePlaybook(const std::string& dir, const std::string& type, std::string year = "2015"); bool parsePlaybookFile(const std::string& fileName, int& sequenceID, std::string year = "2015"); - /* * These three methods augment the playbook */ - void augumentSequencesWithTargets(int sequenceID); + void augumentSequenceWithTargets(int sequenceID); void addSequenceObserver(int sequenceID, std::string name, std::vector payload); void registerTargets(std::vector& potential); diff --git a/include/openspace/util/imagesequencer2.h b/include/openspace/util/imagesequencer2.h new file mode 100644 index 0000000000..4a9982c744 --- /dev/null +++ b/include/openspace/util/imagesequencer2.h @@ -0,0 +1,109 @@ +/***************************************************************************************** +* * +* OpenSpace * +* * +* Copyright (c) 2014 * +* * +* Permission is hereby granted, free of charge, to any person obtaining a copy of this * +* software and associated documentation files (the "Software"), to deal in the Software * +* without restriction, including without limitation the rights to use, copy, modify, * +* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * +* permit persons to whom the Software is furnished to do so, subject to the following * +* conditions: * +* * +* The above copyright notice and this permission notice shall be included in all copies * +* or substantial portions of the Software. * +* * +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * +* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * +* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * +* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * +* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * +* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * +****************************************************************************************/ + +#ifndef __ImageSequencer2_H__ +#define __ImageSequencer2_H__ + +// open space includes +#include +#include +#include +#include +#include +#include + +#include + +namespace openspace { +class ImageSequencer2 { +public: + ImageSequencer2(); + /** + * Singelton instantiation + */ + static ImageSequencer2* _instance; + + static ImageSequencer2& ref(); + static void initialize(); + static void deinitialize(); + + //provides the sequencer with current time + void updateSequencer(double time); + + void runSequenceParser(SequenceParser* parser); + + //translates playbook ambiguous namesetting to spice calls, augments each observation with targets and + //stores all images in its own subset (see _subsetMap member) + bool parsePlaybookFile(const std::string& fileName, + std::string spacecraft, + std::map> acronymDictionary, + std::vector potentialTargets); + + // returns upcoming target + std::pair getNextTarget(); + // returns next target + std::pair getCurrentTarget(); + // returns current target and (in the list) adjacent targets, the number to retrieve is user set + std::pair> getIncidentTargetList(int range = 2); + + double getNextCaptureTime(); + + //a fov class can check whether or not its active + bool instumentActive(std::string instrumentID); + //get all currently active instruments + std::vector getActiveInstruments(); + + const Image* findLatestImageInSubset( ImageSubset& subset); +private: + //default comparison function + bool imageComparer(const Image &a, const Image &b); + + //binary find O(log n) always + std::vector::iterator binary_find(std::vector::iterator begin, + std::vector::iterator end, + const Image &val, + bool(*imageComparer)(const Image &a, const Image &b)); + + //var + double _currentTime; + double _previousTime; + + std::string _defaultCaptureImage; + std::vector _currentlyActiveInstruments; + + std::map _subsetMap; + std::vector> _targetTimes; + std::vector> _instrumentTimes; + //std::vector _activeInstruments + std::map> _acronymDictionary; + + static bool hasData(); + +}; + +} // namespace openspace + + +#endif // __ImageSequencer2_H__ + diff --git a/include/openspace/util/payload.h b/include/openspace/util/payload.h new file mode 100644 index 0000000000..5974e44680 --- /dev/null +++ b/include/openspace/util/payload.h @@ -0,0 +1,47 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2015 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#ifndef __PAYLOAD_H__ +#define __PAYLOAD_H__ + +#include +#include + +namespace openspace { + +class Payload { +public: + static Payload* createFromDictionary(const ghoul::Dictionary& dictionary, const std::string type); + + Payload(const ghoul::Dictionary& dictionary); + virtual ~Payload(); + virtual std::string getType() = 0; + virtual std::vector getSpiceIDs() = 0; +protected: + Payload(); +}; + +} // namespace openspace + +#endif // __PAYLOAD_H__ diff --git a/include/openspace/util/scannerinstrument.h b/include/openspace/util/scannerinstrument.h new file mode 100644 index 0000000000..16aa51b079 --- /dev/null +++ b/include/openspace/util/scannerinstrument.h @@ -0,0 +1,46 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2015 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#ifndef __SCANNERINSTRUMENT_H__ +#define __SCANNERINSTRUMENT_H__ + +#include + +#include + +namespace openspace { + +class ScannerInstrument : public Payload { +public: + ScannerInstrument(const ghoul::Dictionary& dictionary); + virtual std::string getType(); + virtual std::vector getSpiceIDs(); +private: + std::string _type; + std::vector _spiceIDs; +}; + +} // namespace openspace + +#endif // __SCANNERINSTRUMENT_H__ diff --git a/include/openspace/util/sequenceparser.h b/include/openspace/util/sequenceparser.h new file mode 100644 index 0000000000..96d4427c57 --- /dev/null +++ b/include/openspace/util/sequenceparser.h @@ -0,0 +1,71 @@ +/***************************************************************************************** +* * +* OpenSpace * +* * +* Copyright (c) 2014-2015 * +* * +* Permission is hereby granted, free of charge, to any person obtaining a copy of this * +* software and associated documentation files (the "Software"), to deal in the Software * +* without restriction, including without limitation the rights to use, copy, modify, * +* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * +* permit persons to whom the Software is furnished to do so, subject to the following * +* conditions: * +* * +* The above copyright notice and this permission notice shall be included in all copies * +* or substantial portions of the Software. * +* * +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * +* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * +* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * +* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * +* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * +* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * +****************************************************************************************/ + + +#ifndef __SEQUENCEPARSER_H__ +#define __SEQUENCEPARSER_H__ +#include +#include +#include + +#include +#include +#include + +namespace openspace { + struct Image{ + double startTime; + double stopTime; + std::string path; + std::vector activeInstruments; + std::string target; + bool projected; + }; + struct TimeRange{ + TimeRange() : _min(-1), _max(-1){}; + void setRange(double val){ + if (_min > val || _min < 0) _min = val; + if (_max < val || _max < 0) _max = val; + }; + bool inRange(double min, double max){ + return (min >= _min && max <= _max); + } + double _min; + double _max; + }; + struct ImageSubset{ + TimeRange _range; + std::vector < Image > _subset; + }; + +class SequenceParser{ +public: + virtual void create() = 0; + virtual std::map getSubsetMap() = 0; + virtual std::vector> getIstrumentTimes() = 0; + virtual std::vector> getTargetTimes() = 0; + virtual std::map getAcronymDictionary() = 0; +}; +} +#endif //__SEQUENCEPARSER_H__ diff --git a/openspace-data b/openspace-data index 4fed5a4528..6f38f868b6 160000 --- a/openspace-data +++ b/openspace-data @@ -1 +1 @@ -Subproject commit 4fed5a45286c25d593f53920902b5bda0ca6d9c7 +Subproject commit 6f38f868b6ead66776c641095cdf9b9edbf77ec6 diff --git a/scripts/default_startup.lua b/scripts/default_startup.lua index 19cd4413d1..164eff55fc 100644 --- a/scripts/default_startup.lua +++ b/scripts/default_startup.lua @@ -14,7 +14,7 @@ dofile(openspace.absPath('${SCRIPTS}/bind_keys.lua')) -- Load the default keyb -- openspace.time.setDeltaTime(50); -openspace.time.setTime("2015-07-14T10:10:00.00") -- PLUTO +openspace.time.setTime("2015-07-14T11:49:40.00") -- PLUTO -- NH takes series of images from visible to dark side (across terminator) -- Sequence lasts ~10 mins, (recommended dt = 10) diff --git a/src/abuffer/abuffer.cpp b/src/abuffer/abuffer.cpp index cba919f076..fbb12a3b3e 100644 --- a/src/abuffer/abuffer.cpp +++ b/src/abuffer/abuffer.cpp @@ -147,12 +147,12 @@ void ABuffer::resolve() { // Decrease stepsize in volumes if right click is pressed // TODO: Let the interactionhandler handle this - int val = sgct::Engine::getMouseButton(0, SGCT_MOUSE_BUTTON_RIGHT); + /*int val = sgct::Engine::getMouseButton(0, SGCT_MOUSE_BUTTON_RIGHT); float volumeStepFactor = (val) ? 0.2f: 1.0f; if(volumeStepFactor != _volumeStepFactor) { _volumeStepFactor = volumeStepFactor; _resolveShader->setUniform("volumeStepFactor", _volumeStepFactor); - } + }*/ glBindVertexArray(_screenQuad); glDrawArrays(GL_TRIANGLES, 0, 6); diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index ee00946979..132b43e705 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -45,6 +45,8 @@ #include #include #include +#include // testing + #include @@ -101,6 +103,7 @@ OpenSpaceEngine::OpenSpaceEngine(std::string programName) SpiceManager::initialize(); Time::initialize(); ImageSequencer::initialize(); + ImageSequencer2::initialize(); FactoryManager::initialize(); ghoul::systemcapabilities::SystemCapabilities::initialize(); } diff --git a/src/rendering/planets/renderableplanetprojection.cpp b/src/rendering/planets/renderableplanetprojection.cpp index a990de1d95..13ee2d3b3d 100644 --- a/src/rendering/planets/renderableplanetprojection.cpp +++ b/src/rendering/planets/renderableplanetprojection.cpp @@ -36,6 +36,8 @@ #include #include +#include + #include #include #include @@ -48,17 +50,21 @@ namespace { const std::string _loggerCat = "RenderablePlanetProjection"; - const std::string keyProjObserver = "Projection.Observer"; - const std::string keyProjTarget = "Projection.Target"; - const std::string keyProjAberration = "Projection.Aberration"; - const std::string keyInstrument = "Instrument.Name"; - const std::string keyInstrumentFovy = "Instrument.Fovy"; - const std::string keyInstrumentAspect = "Instrument.Aspect"; - const std::string keyInstrumentNear = "Instrument.Near"; - const std::string keyInstrumentFar = "Instrument.Far"; - const std::string keySequenceDir = "Projection.Sequence"; - const std::string keySequenceType = "Projection.SequenceType"; + const std::string keyProjObserver = "Projection.Observer"; + const std::string keyProjTarget = "Projection.Target"; + const std::string keyProjAberration = "Projection.Aberration"; + const std::string keyInstrument = "Instrument.Name"; + const std::string keyInstrumentFovy = "Instrument.Fovy"; + const std::string keyInstrumentAspect = "Instrument.Aspect"; + const std::string keyInstrumentNear = "Instrument.Near"; + const std::string keyInstrumentFar = "Instrument.Far"; + const std::string keySequenceDir = "Projection.Sequence"; + const std::string keySequenceType = "Projection.SequenceType"; const std::string keyPotentialTargets = "PotentialTargets"; + const std::string keyTranslation = "PlaybookTranslation"; + + + const std::string keyFrame = "Frame"; const std::string keyGeometry = "Geometry"; const std::string keyShading = "PerformShading"; @@ -73,6 +79,8 @@ namespace { namespace openspace { +//#define ORIGINAL_SEQUENCER + RenderablePlanetProjection::RenderablePlanetProjection(const ghoul::Dictionary& dictionary) : Renderable(dictionary) , _colorTexturePath("planetTexture", "RGB Texture") @@ -107,12 +115,12 @@ RenderablePlanetProjection::RenderablePlanetProjection(const ghoul::Dictionary& dictionary.getValue(keyFrame, _target); - bool b1 = dictionary.getValue(keyInstrument, _instrumentID); // NH_LORRRI - bool b2 = dictionary.getValue(keyProjObserver, _projectorID); // NH_SPACECRAFT - bool b3 = dictionary.getValue(keyProjTarget, _projecteeID); // PLUTO - bool b4 = dictionary.getValue(keyProjAberration, _aberration); // NONE - bool b5 = dictionary.getValue(keyInstrumentFovy, _fovy); // deg - bool b6 = dictionary.getValue(keyInstrumentAspect, _aspectRatio); // .... + bool b1 = dictionary.getValue(keyInstrument, _instrumentID); + bool b2 = dictionary.getValue(keyProjObserver, _projectorID); + bool b3 = dictionary.getValue(keyProjTarget, _projecteeID); + bool b4 = dictionary.getValue(keyProjAberration, _aberration); + bool b5 = dictionary.getValue(keyInstrumentFovy, _fovy); + bool b6 = dictionary.getValue(keyInstrumentAspect, _aspectRatio); bool b7 = dictionary.getValue(keyInstrumentNear, _nearPlane); bool b8 = dictionary.getValue(keyInstrumentFar, _farPlane); @@ -137,8 +145,6 @@ RenderablePlanetProjection::RenderablePlanetProjection(const ghoul::Dictionary& _potentialTargets[i] = target; } - ImageSequencer::ref().registerTargets(_potentialTargets); - // TODO: textures need to be replaced by a good system similar to the geometry as soon // as the requirements are fixed (ab) std::string texturePath = ""; @@ -160,44 +166,58 @@ RenderablePlanetProjection::RenderablePlanetProjection(const ghoul::Dictionary& addProperty(_projectionTexturePath); _projectionTexturePath.onChange(std::bind(&RenderablePlanetProjection::loadProjectionTexture, this)); - std::string sequenceSource; - bool found = dictionary.getValue(keySequenceDir, sequenceSource); - if (found) { - //LERROR("RenderablePlanetProjection '" << name << "' did not contain a sequence source"); - sequenceSource = absPath(sequenceSource); - //sequenceSource = path + ghoul::filesystem::FileSystem::PathSeparator + sequenceSource; + // std::string sequenceSource; + bool _foundSequence = dictionary.getValue(keySequenceDir, _sequenceSource); + if (_foundSequence) { + _sequenceSource = absPath(_sequenceSource); - std::string sequenceType; - found = dictionary.getValue(keySequenceType, sequenceType); - if (found) { - if (sequenceType == sequenceTypeImage) { - openspace::ImageSequencer::ref().loadSequence(sequenceSource, _sequenceID); - } - else if (sequenceType == sequenceTypePlaybook) { - openspace::ImageSequencer::ref().parsePlaybookFile(sequenceSource, _sequenceID); - } - else { - LERROR("RenderablePlanetProjection '" << name << "' had unknown sequence type '" << sequenceType << "'"); - } - } - ImageSequencer::ref().addSequenceObserver(_sequenceID, "NEW HORIZONS", { "NH_LORRI", - "NH_RALPH_LEISA", - "NH_RALPH_MVIC_PAN1", - "NH_RALPH_MVIC_PAN2", - "NH_RALPH_MVIC_RED", - "NH_RALPH_MVIC_BLUE", - "NH_RALPH_MVIC_FT" }); + _foundSequence = dictionary.getValue(keySequenceType, _sequenceType); + //Important: client must define translation-list in mod file IFF playbook + if (dictionary.hasKey(keyTranslation) && _sequenceType == sequenceTypePlaybook){ + ghoul::Dictionary translationDictionary; + //get translation dictionary + dictionary.getValue(keyTranslation, translationDictionary); + + //get the different instrument types + const std::vector& types = translationDictionary.keys(); + //for each instrument + for (int i = 0; i < types.size(); i++){ + std::string classtype = types[i]; + std::string currentType = keyTranslation + "." + classtype; + //create dictionary containing all {playbookKeys , spice IDs} + ghoul::Dictionary typeDictionary; + dictionary.getValue(keyTranslation + "." + classtype, typeDictionary); + //for each playbook call -> create a Payload object + const std::vector& keys = typeDictionary.keys(); + for (int j = 0; j < keys.size(); j++){ + std::string playbookKey = keys[j]; + std::string currentKey = currentType + "." + playbookKey; + //using dictionary as a way to extract the spiceIDs we need + ghoul::Dictionary spiceDictionary; + dictionary.getValue(currentKey, spiceDictionary); + //create payload + Payload *payload = Payload::createFromDictionary(spiceDictionary, classtype); + //insert payload to map - this will be used in the parser to determine + //behavioral characteristics of each instrument + _fileTranslation[playbookKey] = payload; + } + } + } + else{ + LWARNING("No playbook translation provided, please make sure all spice calls match playbook!"); + } + // Have to delay playbook load in order to augment with targets once current AND spacecraft kernels loaded + for (auto p : _fileTranslation){ + std::vector k = _fileTranslation[p.first]->getSpiceIDs(); + std::cout << "TYPE : " << _fileTranslation[p.first]->getType() << std::endl; + std::cout << "FILE-CALL : " << p.first << std::endl; + std::cout << "SPICE ID'S :" << std::endl; + for (auto r : k){ + std::cout << r << std::endl; + } + std::cout << std::endl; + } } - - //ImageSequencer::ref().augumentSequencesWithTargets(_sequenceID); - - //@TODO planet should broadcast _sequenceID to moons (get-scenegraphnode thing) - if (_projecteeID == "CHARON"){ - _sequenceID = 0; - } - if (_projecteeID == "IO" || _projecteeID == "EUROPA" || _projecteeID == "CALLISTO" || _projecteeID == "GANYMEDE"){ - _sequenceID = 1; - } } RenderablePlanetProjection::~RenderablePlanetProjection(){ @@ -401,14 +421,14 @@ void RenderablePlanetProjection::render(const RenderData& data){ _up = data.camera.lookUpVector(); #ifdef GPU_PROJ - if (_capture){ +/* if (_capture){ for (auto imgSubset : _imageTimes){ - attitudeParameters(imgSubset.first); - _projectionTexturePath = imgSubset.second; + attitudeParameters(imgSubset.first); // projector viewmatrix + _projectionTexturePath = imgSubset.second; // path to current images imageProjectGPU(); //fbopass } _capture = false; - } + }*/ #endif attitudeParameters(_time); _projectionTexturePath = _defaultProjImage; @@ -446,16 +466,36 @@ void RenderablePlanetProjection::update(const UpdateData& data){ // set spice-orientation in accordance to timestamp _time = data.time; _capture = false; - +#ifndef ORIGINAL_SEQUENCER + static bool once; + if (Time::ref().deltaTime() > 0 && !once){ + if (_foundSequence) { + if (_sequenceType == sequenceTypeImage) { + openspace::ImageSequencer::ref().loadSequence(_sequenceSource, _sequenceID); + } + else if (_sequenceType == sequenceTypePlaybook) { + SequenceParser* parser = new HongKangParser(_sequenceSource, + "NEW HORIZONS", + _fileTranslation, + _potentialTargets); + openspace::ImageSequencer2::ref().runSequenceParser(parser); + } + } + once = true; + } + if (Time::ref().deltaTime() > 10){ + openspace::ImageSequencer2::ref().updateSequencer(_time); + } +#else //happens only once //ImageSequencer::ref().augumentSequencesWithTargets(_sequenceID); - + openspace::ImageSequencer::ref().findActiveInstrument(_time, _sequenceID); openspace::ImageSequencer::ref().nextCaptureTime(_time, _sequenceID); - + bool _withinFOV; if (_sequenceID != -1){ - std::string _fovTarget = ""; + std::string _fovTarget = ""; for (int i = 0; i < _potentialTargets.size(); i++){ bool success = openspace::SpiceManager::ref().targetWithinFieldOfView( _instrumentID, @@ -470,15 +510,17 @@ void RenderablePlanetProjection::update(const UpdateData& data){ break; } } - + //if (_projecteeID == _fovTarget){ if (_time >= openspace::ImageSequencer::ref().getNextCaptureTime()){ openspace::ImageSequencer::ref().getImagePath(_imageTimes, _sequenceID, _projecteeID, _withinFOV); - _capture = true; } //} + } + +#endif } void RenderablePlanetProjection::loadProjectionTexture(){ diff --git a/src/rendering/renderablefov.cpp b/src/rendering/renderablefov.cpp index 28687231ea..31f266fed1 100644 --- a/src/rendering/renderablefov.cpp +++ b/src/rendering/renderablefov.cpp @@ -30,6 +30,9 @@ #include #include +#include // testing +#include + #include #include @@ -297,44 +300,46 @@ void RenderableFov::fovProjection(bool H[], std::vector bounds){ glm::dvec3 current; glm::dvec3 next; glm::vec4 tmp(1); - - for (int i = 0; i < 4; i++){ - int k = (i + 1 > 3) ? 0 : i + 1; - current = bounds[i]; - next = bounds[k]; - if (H[i] == false){ // If point is non-interceptive, project it. - insertPoint(_varray2, orthogonalProjection(current), tmp); - } - if (H[i] == true && H[i + 1] == false){ // current point is interceptive, next is not - // find outer most point for interpolation - mid = bisection(current, next, tolerance); - for (int j = 1; j <= _isteps; j++){ - t = ((double)j / _isteps); - // TODO: change the interpolate scheme to place points not on a straight line but instead - // using either slerp or some other viable method (goal: eliminate checkForIntercept -method) - interpolated = interpolate(current, mid, t); - _interceptVector = (j < _isteps) ? checkForIntercept(interpolated) : orthogonalProjection(interpolated); - insertPoint(_varray2, _interceptVector, col_sq); + if (bounds.size() > 1){ + for (int i = 0; i < 4; i++){ + int k = (i + 1 > 4 - 1) ? 0 : i + 1; + + current = bounds[i]; + next = bounds[k]; + if (H[i] == false){ // If point is non-interceptive, project it. + insertPoint(_varray2, orthogonalProjection(current), tmp); + } + if (H[i] == true && H[i + 1] == false){ // current point is interceptive, next is not + // find outer most point for interpolation + mid = bisection(current, next, tolerance); + for (int j = 1; j <= _isteps; j++){ + t = ((double)j / _isteps); + // TODO: change the interpolate scheme to place points not on a straight line but instead + // using either slerp or some other viable method (goal: eliminate checkForIntercept -method) + interpolated = interpolate(current, mid, t); + _interceptVector = (j < _isteps) ? checkForIntercept(interpolated) : orthogonalProjection(interpolated); + insertPoint(_varray2, _interceptVector, col_sq); + } + } + if (H[i] == false && H[i + 1] == true){ // current point is non-interceptive, next is + mid = bisection(next, current, tolerance); + for (int j = 1; j <= _isteps; j++){ + t = ((double)j / _isteps); + interpolated = interpolate(mid, next, t); + _interceptVector = (j > 1) ? checkForIntercept(interpolated) : orthogonalProjection(interpolated); + insertPoint(_varray2, _interceptVector, col_sq); + } + } + if (H[i] == true && H[i + 1] == true){ // both points intercept + for (int j = 0; j <= _isteps; j++){ + t = ((double)j / _isteps); + interpolated = interpolate(current, next, t); + _interceptVector = checkForIntercept(interpolated); + insertPoint(_varray2, _interceptVector, col_sq); + } } } - if (H[i] == false && H[i+1] == true){ // current point is non-interceptive, next is - mid = bisection(next, current, tolerance); - for (int j = 1; j <= _isteps; j++){ - t = ((double)j / _isteps); - interpolated = interpolate(mid, next, t); - _interceptVector = (j > 1) ? checkForIntercept(interpolated) : orthogonalProjection(interpolated); - insertPoint(_varray2, _interceptVector, col_sq); - } - } - if (H[i] == true && H[i + 1] == true){ // both points intercept - for (int j = 0; j <= _isteps; j++){ - t = ((double)j / _isteps); - interpolated = interpolate(current, next, t); - _interceptVector = checkForIntercept(interpolated); - insertPoint(_varray2, _interceptVector, col_sq); - } - } - } + } // only if new points are inserted are we interested in rebuilding the // vbo. Note that this can be optimized but is left as is for now. if (_nrInserted == 0){ @@ -349,7 +354,7 @@ void RenderableFov::fovProjection(bool H[], std::vector bounds){ for (int i = 0; i < _isize[1]; i++) _iarray1[1][i] = i; } - + } void RenderableFov::updateData(){ @@ -391,7 +396,7 @@ void RenderableFov::computeColors(){ col_gray = glm::vec4(0.3, 0.3, 0.3, 1); col_start = glm::vec4(1.00, 0.89, 0.00, 1); col_sq = glm::vec4(1.00, 0.29, 0.00, 1); - + /* col_end.x = c_project.x*t + col_end.x*(1 - t); col_end.y = c_project.y*t + col_end.y*(1 - t); col_end.z = c_project.z*t + col_end.z*(1 - t); @@ -403,6 +408,10 @@ void RenderableFov::computeColors(){ col_sq.x = c_project.x*t + col_sq.x*(1 - t); col_sq.y = c_project.y*t + col_sq.y*(1 - t); col_sq.z = c_project.z*t + col_sq.z*(1 - t); + */ + blue.w = 0.5; + c_project.w = 0.5; + col_end.w = 0.5; } void RenderableFov::render(const RenderData& data){ @@ -423,24 +432,13 @@ void RenderableFov::render(const RenderData& data){ _programObject->setUniform("ModelTransform", transform); setPscUniforms(_programObject, &data.camera, data.position); - // ImageSequencer::ref().findActiveInstrument(_time); - - std::string instrument = ImageSequencer::ref().getActiveInstrument(); - + bool drawFOV = false; - if (instrument == "MVIC"){ - if (_instrumentID == "NH_RALPH_MVIC_PAN1" || - _instrumentID == "NH_RALPH_MVIC_PAN2" || - _instrumentID == "NH_RALPH_MVIC_RED" || - _instrumentID == "NH_RALPH_MVIC_BLUE" || - _instrumentID == "NH_RALPH_MVIC_FT"){ - drawFOV = true; - } - } - else if (instrument == _instrumentID){ - drawFOV = true; + if (Time::ref().deltaTime() > 10){ + drawFOV = ImageSequencer2::ref().instumentActive(_instrumentID); } + if (drawFOV){ // update only when time progresses. if (_oldTime != _time){ @@ -477,12 +475,13 @@ void RenderableFov::render(const RenderData& data){ double targetEpoch; // for each FOV vector - for (int i = 0; i < 4; i++){ + for (int i = 0; i < bounds.size(); i++){ // compute surface intercept openspace::SpiceManager::ref().getSurfaceIntercept(_fovTarget, _spacecraft, _instrumentID, _frame, _method, _aberrationCorrection, _time, targetEpoch, bounds[i], ipoint, ivec, _interceptTag[i]); // if not found, use the orthogonal projected point + if (!_interceptTag[i]) _projectionBounds[i] = orthogonalProjection(bounds[i]); // VBO1 : draw vectors representing outer points of FOV. @@ -512,7 +511,7 @@ void RenderableFov::render(const RenderData& data){ indx += 4; } else{ - glm::vec4 corner(bounds[i][0], bounds[i][1], bounds[i][2], data.position[3] + 1); + glm::vec4 corner(bounds[i][0], bounds[i][1], bounds[i][2], data.position[3] + 2); corner = tmp*corner; // "INFINITE" FOV memcpy(&_varray1[indx], glm::value_ptr(glm::vec4(0)), size); @@ -533,7 +532,12 @@ void RenderableFov::render(const RenderData& data){ glLineWidth(_lineWidth); glBindVertexArray(_vaoID[0]); - glDrawArrays(_mode, 0, _vtotal[0]); + glDrawArrays(GL_TRIANGLE_STRIP, 0, _vtotal[0]); + glBindVertexArray(0); + + glLineWidth(_lineWidth); + glBindVertexArray(_vaoID[0]); + glDrawArrays(GL_LINES, 0, _vtotal[0]); glBindVertexArray(0); //render points diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index f4d34ef607..2842cb1e03 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -24,6 +24,10 @@ #include +#include +#include + + #include #include #include @@ -39,7 +43,6 @@ #include #include #include -#include #include #include #include @@ -507,7 +510,6 @@ namespace openspace { int startY = ySize - 2 * font_size_mono; double currentTime = Time::ref().currentTime(); - ImageSequencer::ref().getActiveInstrument(); double remaining = openspace::ImageSequencer::ref().getNextCaptureTime() - currentTime; double t = 1.f - remaining / openspace::ImageSequencer::ref().getIntervalLength(); @@ -546,9 +548,14 @@ namespace openspace { ); } + std::vector instrVec = ImageSequencer2::ref().getActiveInstruments(); - std::string active = ImageSequencer::ref().getActiveInstrument(); - Freetype::print(font, + std::string active =""; + for (int i = 0; i < instrVec.size(); i++){ + active.append(instrVec[i]); + active.append(" "); + } + Freetype::print(font, _onScreenInformation._position.x * xSize, _onScreenInformation._position.y * ySize - font_size_mono * 3 * 2, glm::vec4(0.3, 0.6, 1, 1), @@ -597,6 +604,7 @@ namespace openspace { PrintText(i++, "Cam->origin: (% .15f, % .4f)", pssl[0], pssl[1]); PrintText(i++, "Scaling: (% .5f, % .5f)", scaling[0], scaling[1]); + double remaining = openspace::ImageSequencer::ref().getNextCaptureTime() - currentTime; double t = 1.f - remaining / openspace::ImageSequencer::ref().getIntervalLength(); std::string progress = "|"; @@ -616,10 +624,58 @@ namespace openspace { } glm::vec4 w(1); glm::vec4 b(0.3, 0.6, 1, 1); - PrintColorText(i++, "Ucoming : %s", 10, w, str.c_str()); + glm::vec4 b2(0.5, 1, 0.5, 1); + PrintColorText(i++, "Ucoming capture : %s", 10, w, str.c_str()); - std::string active = ImageSequencer::ref().getActiveInstrument(); - PrintColorText(i++, "Active Instrument : %s", 10, b, active.c_str()); + + if (Time::ref().deltaTime() > 10){ + std::pair nextTarget = ImageSequencer2::ref().getNextTarget(); + std::pair currentTarget = ImageSequencer2::ref().getCurrentTarget(); + + int timeleft = nextTarget.first - currentTime; + + int hour = timeleft / 3600; + int second = timeleft % 3600; + int minute = second / 60; + second = second % 60; + + std::string hh, mm, ss, coundtown; + + if (hour < 10) hh.append("0"); + if (minute < 10) mm.append("0"); + if (second < 10) ss.append("0"); + + hh.append(std::to_string(hour)); + mm.append(std::to_string(minute)); + ss.append(std::to_string(second)); + + PrintColorText(i++, "Switching observation focus in : [%s:%s:%s]", 10, b2, hh.c_str(), mm.c_str(), ss.c_str()); + + std::pair> incidentTargets = ImageSequencer2::ref().getIncidentTargetList(2); + std::string space; + glm::vec4 color; + int isize = incidentTargets.second.size(); + for (int p = 0; p < isize; p++){ + double t = (double)(p + 1) / (double)(isize+1); + t = (p > isize / 2) ? 1-t : t; + t += 0.3; + color = (p == isize / 2) ? glm::vec4(0, 1, 0, 1) : glm::vec4(t, t, t, 1); + PrintColorText(i, "%s%s", 10, color, space.c_str(), incidentTargets.second[p].c_str()); + for (int k = 0; k < 10; k++){ space += " "; } + } + i++; + + + } + + std::vector instrVec = ImageSequencer2::ref().getActiveInstruments(); + + std::string active = ""; + for (int i = 0; i < instrVec.size(); i++){ + active.append(instrVec[i]); + active.append("\n"); + } + PrintColorText(i++, "Active Instrument : %5s", 10, b, active.c_str()); #undef PrintText } diff --git a/src/scenegraph/spiceephemeris.cpp b/src/scenegraph/spiceephemeris.cpp index 88395676d2..0e42a8f9da 100644 --- a/src/scenegraph/spiceephemeris.cpp +++ b/src/scenegraph/spiceephemeris.cpp @@ -73,6 +73,7 @@ void SpiceEphemeris::update(const UpdateData& data) { glm::dvec3 position(0,0,0); double lightTime = 0.0; + SpiceManager::ref().getTargetPosition(_targetName, _originName, "GALACTIC", "NONE", data.time, position, lightTime); diff --git a/src/util/camerainstrument.cpp b/src/util/camerainstrument.cpp new file mode 100644 index 0000000000..71d820d1ae --- /dev/null +++ b/src/util/camerainstrument.cpp @@ -0,0 +1,50 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2015 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#include + +namespace { + const std::string _loggerCat = "CameraInstrument"; +} + +namespace openspace { + +CameraInstrument::CameraInstrument(const ghoul::Dictionary& dictionary) :_type("CAMERA") +{ + std::string value; + for (int k = 0; k < dictionary.size(); k++){ + dictionary.getValue(std::to_string(k + 1), value); + _spiceIDs.push_back(value); + } +} + +std::string CameraInstrument::getType(){ + return _type; +} + +std::vector CameraInstrument::getSpiceIDs(){ + return _spiceIDs; +} + +} // namespace openspace \ No newline at end of file diff --git a/src/util/factorymanager.cpp b/src/util/factorymanager.cpp index 4dac141501..8ddfc6e1d7 100644 --- a/src/util/factorymanager.cpp +++ b/src/util/factorymanager.cpp @@ -51,6 +51,10 @@ #include #include +#include +#include +#include + // std #include @@ -99,6 +103,10 @@ void FactoryManager::initialize() _manager->factory()->registerClass("Static"); _manager->factory()->registerClass("Spice"); + _manager->addFactory(new ghoul::TemplateFactory); + _manager->factory()->registerClass("Camera"); + _manager->factory()->registerClass("Scanner"); + // Add PlanetGeometry _manager->addFactory(new ghoul::TemplateFactory); _manager->factory() diff --git a/src/util/hongkangparser.cpp b/src/util/hongkangparser.cpp new file mode 100644 index 0000000000..0890192e2f --- /dev/null +++ b/src/util/hongkangparser.cpp @@ -0,0 +1,276 @@ +/***************************************************************************************** +* * +* OpenSpace * +* * +* Copyright (c) 2014 * +* * +* Permission is hereby granted, free of charge, to any person obtaining a copy of this * +* software and associated documentation files (the "Software"), to deal in the Software * +* without restriction, including without limitation the rights to use, copy, modify, * +* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * +* permit persons to whom the Software is furnished to do so, subject to the following * +* conditions: * +* * +* The above copyright notice and this permission notice shall be included in all copies * +* or substantial portions of the Software. * +* * +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * +* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * +* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * +* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * +* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * +* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * +****************************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace { + const std::string _loggerCat = "HongKangParser"; +} + +namespace openspace { +HongKangParser::HongKangParser(const std::string& fileName, + std::string spacecraft, + std::map fileTranslation, + std::vector potentialTargets) : + _defaultCaptureImage(absPath("C:/Users/michal/openspace/openspace-data/scene/common/textures/placeholder_blank.png")) +{ + _fileName = fileName; + _spacecraft = spacecraft; + _fileTranslation = fileTranslation; + _potentialTargets = potentialTargets; +} + +void HongKangParser::create(){ + if (size_t position = _fileName.find_last_of(".") + 1){ + if (position != std::string::npos){ + std::string extension = ghoul::filesystem::File(_fileName).fileExtension(); + + if (extension == "txt"){// Hong Kang. pre-parsed playbook + LINFO("Using Preparsed Playbook V9H"); + std::ifstream file(_fileName); + if (!file.good()) LERROR("Failed to open txt file '" << _fileName << "'"); + + std::string timestr = ""; + double shutter = 0.01; + double startTime, stopTime; + + // for augmentation we only need the keys in acronymDictionary as a vector + std::vector payload; + for (auto p : _acronymDictionary) + for (auto t : p.second) + payload.push_back(t); + payload.erase(std::unique(payload.begin(), payload.end()), payload.end()); + + std::string previousInstrument; + std::string previousTarget; + + double longExposureStart = 0; + double longExposureStop = 0; + std::string longExposureKeyword; + + do{ + std::getline(file, timestr); + //For each instrument in acronym dictionary + for (auto it : _acronymDictionary){ + // check if first col in line has keyword of interest + std::string keyword = timestr.substr(0, timestr.find_first_of(" ")); + auto pos = keyword.find(it.first); + if (pos != std::string::npos){ + // grab the time + std::string met = timestr.substr(24, 9); + //convert to ephemeris time + startTime = getETfromMet(met); + /* + std::string checkIfMVIC = "MVIC"; + int count = 0; + bool foundStopTime = false; + if (findExactMatch("MVIC", keyword)){ + std::string abortLine; + int len = file.tellg(); + while (!file.eof() && !findExactMatch("ABORT", abortLine)){ + + std::getline(file, abortLine); + std::string abortCommand = abortLine.substr(0, abortLine.find_first_of(" ")); + count++; + if (findExactMatch("ABORT", abortCommand)){ + met = abortLine.substr(24, 9); + stopTime = getETfromMet(met); + foundStopTime = true; + } + } + file.seekg(len, std::ios_base::beg); + }else{ + //assume regular shutter speed; + stopTime = startTime + shutter; + } + + if (foundStopTime){ + longExposureStart = startTime; + longExposureStop = stopTime; + longExposureKeyword = keyword; + }*/ + + // retrieve corresponding SPICE call + std::vector instrument = it.second; + + // create image + Image image; + //stoptime- quick setting for now + stopTime = startTime + 0.01; + createImage(image, startTime, stopTime, instrument, "", _defaultCaptureImage); + // add targets + augmentWithSpice(image, _spacecraft, payload, _potentialTargets); + + //SKA ERSATTAS MED NAGOT ANNAT - "instrument times" + if (previousInstrument != it.first){ + previousInstrument = it.first; + std::pair v_time = std::make_pair(image.startTime, keyword); + _instrumentTimes.push_back(v_time); + } + + if (previousTarget != image.target){ + previousTarget = image.target; + std::pair v_target = std::make_pair(image.startTime, image.target); + _targetTimes.push_back(v_target); + } + + //_subsetMap[image.target]._subset[keyword].push_back(image); + _subsetMap[image.target]._subset.push_back(image); + _subsetMap[image.target]._range.setRange(image.startTime); + } + } + } while (!file.eof()); + } + } + } + //PRINT TO FILE FUNCTION + std::ofstream myfile; + myfile.open("HongKangOutput.txt"); + + //print all + for (auto target : _subsetMap){ + std::string min, max; + SpiceManager::ref().getDateFromET(target.second._range._min, min); + SpiceManager::ref().getDateFromET(target.second._range._max, max); + + myfile << std::endl; + for (auto image : target.second._subset){ + std::string time; + SpiceManager::ref().getDateFromET(image.startTime, time); + myfile << std::fixed + << std::setw(10) << time + << std::setw(10) << (int)getMetFromET(image.startTime) + << std::setw(10) << image.target << std::setw(10); + for (auto instrument : image.activeInstruments){ + myfile << " " << instrument; + } + myfile << std::endl; + } + } + myfile.close(); +} + +bool HongKangParser::augmentWithSpice(Image& image, + std::string spacecraft, + std::vector payload, + std::vector potentialTargets){ + image.target = "VOID"; + // we have (?) to cast to int, unfortunately + int exposureTime = image.stopTime - image.startTime; + if (exposureTime == 0) exposureTime = 1; + double et; + for (int i = 0; i < potentialTargets.size(); i++){ + bool success = false; + bool _withinFOV = false; + for (int j = 0; j < image.activeInstruments.size(); j++){ + double time = image.startTime; + for (int k = 0; k < exposureTime; k++){ + time += k; + success = openspace::SpiceManager::ref().targetWithinFieldOfView( + image.activeInstruments[j], + potentialTargets[i], + spacecraft, + "ELLIPSOID", + "NONE", + time, + _withinFOV); + if (_withinFOV){ + image.target = potentialTargets[i]; + _withinFOV = false; + } + } + } + } + return false; +} + +void HongKangParser::createImage(Image& image, double startTime, double stopTime, std::vector instr, std::string targ, std::string pot) { + image.startTime = startTime; + image.stopTime = stopTime; + image.path = pot; + for (int i = 0; i < instr.size(); i++){ + image.activeInstruments.push_back(instr[i]); + } + image.target = targ; + image.projected = false; +} + +double HongKangParser::getETfromMet(std::string timestr){ + std::string::size_type sz; + return getETfromMet(std::stod(timestr, &sz)); +} + +double HongKangParser::getETfromMet(double met){ + double diff; + double referenceET; + double et; + openspace::SpiceManager::ref().getETfromDate("2015-07-14T11:50:00.00", referenceET); + double missionLaunch = referenceET - _metRef; + + diff = abs(met - _metRef); + if (met > _metRef){ + et = referenceET + diff; + }else if (met < _metRef){ + et = referenceET - diff; + } + return et; +} + + +double HongKangParser::getMetFromET(double et){ + double met; + double referenceET; + openspace::SpiceManager::ref().getETfromDate("2015-07-14T11:50:00.00", referenceET); + + if (et >= referenceET){ + met = _metRef + (et - referenceET); + } + else{ + met = _metRef - (referenceET - et); + } + + return met; +} + +std::map HongKangParser::getSubsetMap(){ + return _subsetMap; +} +std::vector> HongKangParser::getIstrumentTimes(){ + return _instrumentTimes; +} +std::vector> HongKangParser::getTargetTimes(){ + return _targetTimes; +} +} \ No newline at end of file diff --git a/src/util/imagesequencer.cpp b/src/util/imagesequencer.cpp index 831c460eea..cd16be7963 100644 --- a/src/util/imagesequencer.cpp +++ b/src/util/imagesequencer.cpp @@ -52,13 +52,16 @@ struct ImageParams{ bool projected; }; -bool imageComparer (const ImageParams &a, const ImageParams &b){ - return a.startTime < b.startTime; -}; + std::vector> _timeStamps; void createImage(std::vector& vec, double t1, std::string instrument, std::string target, std::string path = "dummypath"); +auto imageComparer = [](const ImageParams &a, const ImageParams &b)->bool{ + return a.startTime < b.startTime; +}; + + std::vector::iterator binary_find(std::vector::iterator begin, std::vector::iterator end, const ImageParams &val, @@ -153,7 +156,6 @@ double ImageSequencer::nextCaptureTime(double time, int sequenceID){ std::string ImageSequencer::findActiveInstrument(double time, int sequenceID){ auto it = binary_find(_timeStamps[sequenceID].begin(), _timeStamps[sequenceID].end(), { time, "", "", "",false }, imageComparer); - if ((it == _timeStamps[sequenceID].end())){ _activeInstrument = "Not found, incufficient playbook-data"; }else{ @@ -163,7 +165,7 @@ std::string ImageSequencer::findActiveInstrument(double time, int sequenceID){ return _activeInstrument; } -void ImageSequencer::augumentSequencesWithTargets(int sequenceID){ +void ImageSequencer::augumentSequenceWithTargets(int sequenceID){ if (!_targetsAdded){ // if there is an registered observer for this sequence if (_observers.count(sequenceID) > 0) { @@ -210,17 +212,17 @@ void ImageSequencer::augumentSequencesWithTargets(int sequenceID){ } bool ImageSequencer::getImagePath(std::vector>& _imageTimes, int sequenceID, std::string projectee, bool withinFOV){ - if (withinFOV && !Time::ref().timeJumped()){ + /*if (withinFOV && !Time::ref().timeJumped()){ getSingleImage(_imageTimes, sequenceID, projectee); - }else{ + }else{*/ getMultipleImages(_imageTimes, sequenceID, projectee); - } + //} return true; } bool ImageSequencer::getMultipleImages(std::vector>& _imageTimes, int sequenceID, std::string projectee){ double previousTime; - std::map::iterator it = _projectableTargets.find(projectee); + std::map::iterator it = _projectableTargets.find(projectee); if (it != _projectableTargets.end()){ previousTime = it->second; it->second = _currentTime; diff --git a/src/util/imagesequencer2.cpp b/src/util/imagesequencer2.cpp new file mode 100644 index 0000000000..9106319477 --- /dev/null +++ b/src/util/imagesequencer2.cpp @@ -0,0 +1,335 @@ +/***************************************************************************************** +* * +* OpenSpace * +* * +* Copyright (c) 2014 * +* * +* Permission is hereby granted, free of charge, to any person obtaining a copy of this * +* software and associated documentation files (the "Software"), to deal in the Software * +* without restriction, including without limitation the rights to use, copy, modify, * +* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * +* permit persons to whom the Software is furnished to do so, subject to the following * +* conditions: * +* * +* The above copyright notice and this permission notice shall be included in all copies * +* or substantial portions of the Software. * +* * +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * +* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * +* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * +* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * +* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * +* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * +****************************************************************************************/ + +// open space includes +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace { +const std::string _loggerCat = "ImageSequencer2"; +} + +namespace openspace { + +ImageSequencer2* ImageSequencer2::_instance = nullptr; + +ImageSequencer2::ImageSequencer2() : +_defaultCaptureImage(absPath("C:/Users/michal/openspace/openspace-data/scene/common/textures/placeholder_blank.png")) +{} + + +ImageSequencer2& ImageSequencer2::ref() { + assert(_instance != nullptr); + return *_instance; +} +void ImageSequencer2::initialize() { + assert(_instance == nullptr); + _instance = new ImageSequencer2; +} + +void ImageSequencer2::deinitialize() { + delete _instance; + _instance = nullptr; +} +/* +auto cmp = [](const Image &a, const Image &b)->bool{ + return a.startTime < b.startTime; +};*/ + +bool ImageSequencer2::imageComparer(const Image &a, const Image &b){ + return a.startTime < b.startTime; +}; + +std::vector::iterator ImageSequencer2::binary_find(std::vector::iterator begin, + std::vector::iterator end, + const Image &val, + bool(*compareFunc)(const Image &a, const Image &b)){ + // Finds the lower bound in at most log(last - first) + 1 comparisons + std::vector::iterator it = std::lower_bound(begin, end, val, compareFunc); + if (it != begin){ + return it; + } + return end; +} + +void ImageSequencer2::updateSequencer(double time){ + if (_currentTime != time){ + _previousTime = _currentTime; + _currentTime = time; + } +} + +std::pair ImageSequencer2::getNextTarget(){ + // make into template func + auto compareTime = [](const std::pair &a, + const std::pair &b)->bool{ + return a.first < b.first; + }; + std::pair findEqualToThis; + findEqualToThis.first = _currentTime; + auto it = std::lower_bound(_targetTimes.begin(), _targetTimes.end(), findEqualToThis, compareTime); + + if (it != _targetTimes.end()){ + return (*it); + } +} + +std::pair ImageSequencer2::getCurrentTarget(){ + // make into template func + auto compareTime = [](const std::pair &a, + const std::pair &b)->bool{ + return a.first < b.first; + }; + std::pair findEqualToThis; + findEqualToThis.first = _currentTime; + auto it = std::lower_bound(_targetTimes.begin(), _targetTimes.end(), findEqualToThis, compareTime); + + if (it != _targetTimes.end()){ + return *std::prev(it); + } +} + +std::pair> ImageSequencer2::getIncidentTargetList(int range){ + std::pair> incidentTargets; + + auto compareTime = [](const std::pair &a, + const std::pair &b)->bool{ + return a.first < b.first; + }; + std::pair findEqualToThis; + findEqualToThis.first = _currentTime; + auto it = std::lower_bound(_targetTimes.begin(), _targetTimes.end(), findEqualToThis, compareTime); + + std::advance(it, -(range+1)); + + for (int i = 0; i < 2*range+1; i++){ + incidentTargets.first = it->first; + incidentTargets.second.push_back(it->second); + it++; + if (it == _targetTimes.end()) + break; + } + + return incidentTargets; +} + +std::vector ImageSequencer2::getActiveInstruments(){ + return _currentlyActiveInstruments; +} +bool ImageSequencer2::instumentActive(std::string instrumentID){ + // make into template func + auto compareTime = [](const std::pair &a, + const std::pair &b)->bool{ + return a.first < b.first; + }; + + std::pair findEqualToThis; + findEqualToThis.first = _currentTime; + auto it = std::lower_bound(_instrumentTimes.begin(), _instrumentTimes.end(), findEqualToThis, compareTime); + + it = std::prev(it); + if (it != _instrumentTimes.end()){ + std::string key = it->second; + std::vector instruments = _acronymDictionary[key]; + for (auto i : instruments){ + if (i == instrumentID){ + _currentlyActiveInstruments = instruments; + return true; + } + } + } + return false; +} + +double ImageSequencer2::getNextCaptureTime(){ + // to do this we need getCurrentTarget to ALWAYS work! + return 0.0; +} + +void ImageSequencer2::runSequenceParser(SequenceParser* parser){ + parser->create(); + + _subsetMap = parser->getSubsetMap(); + _instrumentTimes = parser->getIstrumentTimes(); + //_targetTimes = parser->getTargetTimes(); + _acronymDictionary = parser->getAcronymDictionary(); +} + +/* +bool ImageSequencer2::parsePlaybookFile(const std::string& fileName, + std::string spacecraft, + std::map> acronymDictionary, + std::vector potentialTargets) { + _acronymDictionary = acronymDictionary; + if (size_t position = fileName.find_last_of(".") + 1){ + if (position != std::string::npos){ + std::string extension = ghoul::filesystem::File(fileName).fileExtension(); + + if (extension == "txt"){// Hong Kang. pre-parsed playbook + LINFO("Using Preparsed Playbook V9H"); + std::ifstream file(fileName); + if (!file.good()) LERROR("Failed to open txt file '" << fileName << "'"); + + std::string timestr = ""; + double shutter = 0.01; + double startTime, stopTime; + + // for augmentation we only need the keys in acronymDictionary as a vector + std::vector payload; + for (auto p : acronymDictionary) + for (auto t : p.second) + payload.push_back(t); + payload.erase(std::unique(payload.begin(), payload.end()), payload.end()); + + std::string previousInstrument; + std::string previousTarget; + + double longExposureStart = 0; + double longExposureStop = 0; + std::string longExposureKeyword; + + do{ + std::getline(file, timestr); + //For each instrument in acronym dictionary + for (auto it : _acronymDictionary){ + // check if first col in line has keyword of interest + std::string keyword = timestr.substr(0, timestr.find_first_of(" ")); + auto pos = keyword.find(it.first); + if (pos != std::string::npos){ + // grab the time + std::string met = timestr.substr(24, 9); + //convert to ephemeris time + startTime = getETfromMet(met); + + //std::string checkIfMVIC = "MVIC"; + //int count = 0; + //bool foundStopTime = false; + //if (findExactMatch("MVIC", keyword)){ + // std::string abortLine; + // int len = file.tellg(); + // while (!file.eof() && !findExactMatch("ABORT", abortLine)){ + // + // std::getline(file, abortLine); + // std::string abortCommand = abortLine.substr(0, abortLine.find_first_of(" ")); + // count++; + // if (findExactMatch("ABORT", abortCommand)){ + // met = abortLine.substr(24, 9); + // stopTime = getETfromMet(met); + // foundStopTime = true; + // } + // } + // file.seekg(len, std::ios_base::beg); + //}else{ + // //assume regular shutter speed; + // stopTime = startTime + shutter; + //} + // + //if (foundStopTime){ + // longExposureStart = startTime; + // longExposureStop = stopTime; + // longExposureKeyword = keyword; + //} + + // retrieve corresponding SPICE call + std::vector instrument = it.second; + + // create image + Image image; + //stoptime- quick setting for now + stopTime = startTime + 0.01; + createImage(image, startTime, stopTime, instrument, "", _defaultCaptureImage); + // add targets + augmentWithSpice(image, spacecraft, payload, potentialTargets); + + //SKA ERSATTAS MED NAGOT ANNAT - "instrument times" + if (previousInstrument != it.first){ + previousInstrument = it.first; + std::pair v_time = std::make_pair(image.startTime, keyword); + _instrumentTimes.push_back(v_time); + } + + if (previousTarget != image.target ){ + previousTarget = image.target; + std::pair v_target = std::make_pair(image.startTime, image.target); + _targetTimes.push_back(v_target); + } + + //_subsetMap[image.target]._subset[keyword].push_back(image); + _subsetMap[image.target]._subset.push_back(image); + _subsetMap[image.target]._range.setRange(image.startTime); + } + } + } while (!file.eof()); + } + } + } + + //PRINT FUNCTION + std::string st1 = "2015-07-14T10:00:00.00"; + std::string st2 = "2015-07-14T12:00:00.00"; + double start, stop; + + SpiceManager::ref().getETfromDate(st1, start); + SpiceManager::ref().getETfromDate(st2, stop); + + std::ofstream myfile; + myfile.open("augmentedPef.txt"); + + //print all + for (auto target : _subsetMap){ + std::string min, max; + SpiceManager::ref().getDateFromET(target.second._range._min, min); + SpiceManager::ref().getDateFromET(target.second._range._max, max); + + myfile << std::endl; + for (auto image : target.second._subset){ + std::string time; + SpiceManager::ref().getDateFromET(image.startTime, time); + myfile << std::fixed + << std::setw(10) << time + << std::setw(10) << (int)getMetFromET(image.startTime) + << std::setw(10) << image.target << std::setw(10); + for (auto instrument : image.activeInstruments){ + myfile << " " << instrument; + } + myfile << std::endl; + } + } + + myfile.close(); + + return true; +} +*/ +} // namespace openspace diff --git a/src/util/payload.cpp b/src/util/payload.cpp new file mode 100644 index 0000000000..d7c23fdbbe --- /dev/null +++ b/src/util/payload.cpp @@ -0,0 +1,59 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2015 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#include +#include + +namespace { +const std::string _loggerCat = "Payload"; +} + +namespace openspace { + +Payload* Payload::createFromDictionary(const ghoul::Dictionary& dictionary, const std::string type) +{ + ghoul::TemplateFactory* factory + = FactoryManager::ref().factory(); + Payload* result = factory->create(type, dictionary); + + if (result == nullptr) { + LERROR("Failed creating Payload object of type '" << type << "'"); + return nullptr; + } + return result; +} + +Payload::Payload() +{ +} + +Payload::Payload(const ghoul::Dictionary& dictionary) +{ +} + +Payload::~Payload() +{ +} + +} // namespace openspace \ No newline at end of file diff --git a/src/util/scannerinstrument.cpp b/src/util/scannerinstrument.cpp new file mode 100644 index 0000000000..e93ec43efe --- /dev/null +++ b/src/util/scannerinstrument.cpp @@ -0,0 +1,49 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2015 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#include + +namespace { + const std::string _loggerCat = "ScannerInstrument"; +} + +namespace openspace { + +ScannerInstrument::ScannerInstrument(const ghoul::Dictionary& dictionary) : _type("SCANNER") +{ + std::string value; + for (int k = 0; k < dictionary.size(); k++){ + dictionary.getValue(std::to_string(k + 1), value); + _spiceIDs.push_back(value); + } +} +std::string ScannerInstrument::getType(){ + return _type; +} + +std::vector ScannerInstrument::getSpiceIDs(){ + return _spiceIDs; +} + +} // namespace openspace \ No newline at end of file