Compare commits

..

No commits in common. "82938b4f526d84c86f82f7131abf897c81ee6d79" and "f7c0d0a844810f38bc99a022f8a602b97602374a" have entirely different histories.

8 changed files with 325 additions and 442 deletions

View File

@ -9,6 +9,7 @@
#include "entities/Entity.h" #include "entities/Entity.h"
#include "common/SpdLogger.h" #include "common/SpdLogger.h"
//#include "scutcheon/osgScutcheon.h"
LabelComponent::LabelComponent(SceneComponent* parent) LabelComponent::LabelComponent(SceneComponent* parent)
: SceneComponent(parent) : SceneComponent(parent)

View File

@ -38,7 +38,7 @@ public:
template<class T> template<class T>
T* GetComponent() { T* GetComponent() {
for (auto& componet : children_) { for (auto& componet : children_) {
if (componet->GetSelfTypeName() == T::GetTypeName()) { if (componet->GetTypeName() == T::GetTypeName()) {
return reinterpret_cast<T*>(componet); return reinterpret_cast<T*>(componet);
} }
} }

View File

@ -1,7 +1,6 @@
#include "entities/TrajectoryTraceComponent.h" #include "entities/TrajectoryTraceComponent.h"
#include <algorithm> #include <algorithm>
#include <cmath>
#include <osg/BlendFunc> #include <osg/BlendFunc>
#include <osg/Depth> #include <osg/Depth>
@ -91,7 +90,6 @@ void TrajectoryTraceComponent::Begin() {
sampleAccum_ = 0.0; sampleAccum_ = 0.0;
elapsedTime_ = 0.0; elapsedTime_ = 0.0;
hasLastSample_ = false; hasLastSample_ = false;
traceRestartPending_ = false;
attachedToScene_ = false; attachedToScene_ = false;
ClearTrace(); ClearTrace();
} }
@ -109,14 +107,6 @@ void TrajectoryTraceComponent::Update(double dt) {
TrimExpiredPoints(); TrimExpiredPoints();
const osg::Vec3d currentPos = entity->GetTransform()->GetLocation(); const osg::Vec3d currentPos = entity->GetTransform()->GetLocation();
if (traceRestartPending_) {
lastSamplePos_ = currentPos;
hasLastSample_ = true;
sampleAccum_ = 0.0;
traceRestartPending_ = false;
return;
}
if (!hasLastSample_) { if (!hasLastSample_) {
osg::Vec3d initialPos = currentPos; osg::Vec3d initialPos = currentPos;
if (PathComponent* pathComponent = entity->GetComponent<PathComponent>()) { if (PathComponent* pathComponent = entity->GetComponent<PathComponent>()) {
@ -220,8 +210,11 @@ double TrajectoryTraceComponent::GetMinMoveDistance() const {
void TrajectoryTraceComponent::SetMaxPoints(int maxPoints) { void TrajectoryTraceComponent::SetMaxPoints(int maxPoints) {
maxPoints_ = std::max(2, maxPoints); maxPoints_ = std::max(2, maxPoints);
if (vertices_.valid() && static_cast<int>(vertices_->size()) > maxPoints_) { if (vertices_.valid() && static_cast<int>(vertices_->size()) > maxPoints_) {
TrimOverflowPoints(); const int overflow = static_cast<int>(vertices_->size()) - maxPoints_;
DirtyGeometry(); vertices_->erase(vertices_->begin(), vertices_->begin() + overflow);
drawArrays_->setCount(static_cast<GLsizei>(vertices_->size()));
vertices_->dirty();
geometry_->dirtyBound();
} }
} }
@ -278,7 +271,6 @@ double TrajectoryTraceComponent::GetGapLength() const {
void TrajectoryTraceComponent::SetDashScrollSpeed(double speed) { void TrajectoryTraceComponent::SetDashScrollSpeed(double speed) {
dashScrollSpeed_ = speed; dashScrollSpeed_ = speed;
DirtyGeometry();
} }
double TrajectoryTraceComponent::GetDashScrollSpeed() const { double TrajectoryTraceComponent::GetDashScrollSpeed() const {
@ -288,18 +280,17 @@ double TrajectoryTraceComponent::GetDashScrollSpeed() const {
void TrajectoryTraceComponent::ClearTrace() { void TrajectoryTraceComponent::ClearTrace() {
InitializeGeometry(); InitializeGeometry();
Entity* entity = GetEntity();
if (nullptr != entity && nullptr != entity->GetTransform()) {
lastSamplePos_ = entity->GetTransform()->GetLocation();
}
vertices_->clear(); vertices_->clear();
renderVertices_->clear();
sampleTimes_.clear(); sampleTimes_.clear();
hasLastSample_ = true; drawArrays_->setCount(0);
sampleAccum_ = 0.0; vertices_->dirty();
traceRestartPending_ = true; geometry_->dirtyBound();
DirtyGeometry(); if (geode_.valid()) {
geode_->dirtyBound();
}
if (mt_.valid()) {
mt_->dirtyBound();
}
} }
void TrajectoryTraceComponent::InitializeGeometry() { void TrajectoryTraceComponent::InitializeGeometry() {
@ -311,15 +302,15 @@ void TrajectoryTraceComponent::InitializeGeometry() {
geode_ = new osg::Geode; geode_ = new osg::Geode;
geometry_ = new osg::Geometry; geometry_ = new osg::Geometry;
vertices_ = new osg::Vec3Array; vertices_ = new osg::Vec3Array;
renderVertices_ = new osg::Vec3Array;
colors_ = new osg::Vec4Array; colors_ = new osg::Vec4Array;
drawArrays_ = new osg::DrawArrays(GL_LINE_STRIP, 0, 0); drawArrays_ = new osg::DrawArrays(GL_LINE_STRIP, 0, 0);
lineWidthState_ = new osg::LineWidth(lineWidth_); lineWidthState_ = new osg::LineWidth(lineWidth_);
lineStippleState_ = new osg::LineStipple(1, 0xFFFF);
geometry_->setDataVariance(osg::Object::DYNAMIC); geometry_->setDataVariance(osg::Object::DYNAMIC);
geometry_->setUseDisplayList(false); geometry_->setUseDisplayList(false);
geometry_->setUseVertexBufferObjects(true); geometry_->setUseVertexBufferObjects(true);
geometry_->setVertexArray(renderVertices_.get()); geometry_->setVertexArray(vertices_.get());
geometry_->addPrimitiveSet(drawArrays_.get()); geometry_->addPrimitiveSet(drawArrays_.get());
colors_->push_back(color_); colors_->push_back(color_);
@ -332,6 +323,7 @@ void TrajectoryTraceComponent::InitializeGeometry() {
stateSet->setAttributeAndModes(new osg::BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); stateSet->setAttributeAndModes(new osg::BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
stateSet->setAttributeAndModes(new osg::Depth(osg::Depth::LEQUAL, 0.0, 1.0, false)); stateSet->setAttributeAndModes(new osg::Depth(osg::Depth::LEQUAL, 0.0, 1.0, false));
stateSet->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); stateSet->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
stateSet->setAttributeAndModes(lineStippleState_.get(), osg::StateAttribute::OFF);
geode_->addDrawable(geometry_.get()); geode_->addDrawable(geometry_.get());
mt_->addChild(geode_.get()); mt_->addChild(geode_.get());
@ -357,8 +349,23 @@ bool TrajectoryTraceComponent::AppendPoint(const osg::Vec3d& geoPoint) {
vertices_->push_back(worldPoint); vertices_->push_back(worldPoint);
sampleTimes_.push_back(elapsedTime_); sampleTimes_.push_back(elapsedTime_);
TrimOverflowPoints(); if (static_cast<int>(vertices_->size()) > maxPoints_) {
DirtyGeometry(); const int overflow = static_cast<int>(vertices_->size()) - maxPoints_;
vertices_->erase(vertices_->begin(), vertices_->begin() + overflow);
for (int i = 0; i < overflow && !sampleTimes_.empty(); ++i) {
sampleTimes_.pop_front();
}
}
drawArrays_->setCount(static_cast<GLsizei>(vertices_->size()));
vertices_->dirty();
geometry_->dirtyBound();
if (geode_.valid()) {
geode_->dirtyBound();
}
if (mt_.valid()) {
mt_->dirtyBound();
}
if (attachedToScene_ && mt_->getNumParents() == 0) { if (attachedToScene_ && mt_->getNumParents() == 0) {
AttachTraceToScene(); AttachTraceToScene();
@ -382,7 +389,15 @@ bool TrajectoryTraceComponent::UpdateTailPoint(const osg::Vec3d& geoPoint) {
if (!sampleTimes_.empty()) { if (!sampleTimes_.empty()) {
sampleTimes_.back() = elapsedTime_; sampleTimes_.back() = elapsedTime_;
} }
DirtyGeometry(); drawArrays_->setCount(static_cast<GLsizei>(vertices_->size()));
vertices_->dirty();
geometry_->dirtyBound();
if (geode_.valid()) {
geode_->dirtyBound();
}
if (mt_.valid()) {
mt_->dirtyBound();
}
if (attachedToScene_ && mt_->getNumParents() == 0) { if (attachedToScene_ && mt_->getNumParents() == 0) {
AttachTraceToScene(); AttachTraceToScene();
@ -448,7 +463,15 @@ void TrajectoryTraceComponent::TrimExpiredPoints() {
} }
if (removed) { if (removed) {
DirtyGeometry(); drawArrays_->setCount(static_cast<GLsizei>(vertices_->size()));
vertices_->dirty();
geometry_->dirtyBound();
if (geode_.valid()) {
geode_->dirtyBound();
}
if (mt_.valid()) {
mt_->dirtyBound();
}
} }
} }
@ -464,101 +487,34 @@ void TrajectoryTraceComponent::UpdateStyle() {
lineWidthState_->setWidth(lineWidth_); lineWidthState_->setWidth(lineWidth_);
} }
DirtyGeometry(); if (lineStippleState_.valid() && geode_.valid()) {
} const double cycle = std::max(1.0, dashLength_ + gapLength_);
double factorValue = cycle / std::max(1.0f, lineWidth_);
void TrajectoryTraceComponent::DirtyGeometry() { if (factorValue < 1.0) {
if (!geometry_.valid() || !drawArrays_.valid() || !renderVertices_.valid()) { factorValue = 1.0;
return; } else if (factorValue > 255.0) {
} factorValue = 255.0;
RebuildRenderGeometry();
renderVertices_->dirty();
geometry_->dirtyDisplayList();
geometry_->dirtyBound();
if (geode_.valid()) {
geode_->dirtyBound();
}
if (mt_.valid()) {
mt_->dirtyBound();
}
}
void TrajectoryTraceComponent::TrimOverflowPoints() {
if (!vertices_.valid()) {
return;
}
if (static_cast<int>(vertices_->size()) <= maxPoints_) {
return;
}
const int overflow = static_cast<int>(vertices_->size()) - maxPoints_;
vertices_->erase(vertices_->begin(), vertices_->begin() + overflow);
for (int i = 0; i < overflow && !sampleTimes_.empty(); ++i) {
sampleTimes_.pop_front();
}
}
void TrajectoryTraceComponent::RebuildRenderGeometry() {
if (!renderVertices_.valid()) {
return;
}
renderVertices_->clear();
if (!vertices_.valid() || vertices_->empty()) {
drawArrays_->setMode(GL_LINE_STRIP);
drawArrays_->setCount(0);
return;
}
if (!dashed_ || vertices_->size() < 2) {
drawArrays_->setMode(GL_LINE_STRIP);
renderVertices_->assign(vertices_->begin(), vertices_->end());
drawArrays_->setCount(static_cast<GLsizei>(renderVertices_->size()));
return;
}
drawArrays_->setMode(GL_LINES);
const double cycle = std::max(0.001, dashLength_ + gapLength_);
double dashOffset = std::fmod(elapsedTime_ * dashScrollSpeed_, cycle);
if (dashOffset < 0.0) {
dashOffset += cycle;
}
double accumulatedDistance = 0.0;
for (std::size_t i = 1; i < vertices_->size(); ++i) {
const osg::Vec3d& start = (*vertices_)[i - 1];
const osg::Vec3d& end = (*vertices_)[i];
const osg::Vec3d segment = end - start;
const double segmentLength = segment.length();
if (segmentLength <= 1e-6) {
continue;
} }
int factor = static_cast<int>(factorValue);
const osg::Vec3d direction = segment / segmentLength; int onBits = static_cast<int>(std::round(16.0 * dashLength_ / cycle));
double localDistance = 0.0; if (onBits < 1) {
while (localDistance < segmentLength) { onBits = 1;
double phase = std::fmod(accumulatedDistance + localDistance + dashOffset, cycle); } else if (onBits > 15) {
if (phase < 0.0) { onBits = 15;
phase += cycle; }
} unsigned short pattern = 0;
for (int i = 0; i < 16; ++i) {
if (phase < dashLength_) { if (i < onBits) {
const double visibleLength = std::min(dashLength_ - phase, segmentLength - localDistance); pattern |= static_cast<unsigned short>(1u << i);
const osg::Vec3d visibleStart = start + direction * localDistance;
const osg::Vec3d visibleEnd = start + direction * (localDistance + visibleLength);
renderVertices_->push_back(visibleStart);
renderVertices_->push_back(visibleEnd);
localDistance += visibleLength;
} else {
localDistance += std::min(cycle - phase, segmentLength - localDistance);
} }
} }
if (!dashed_) {
accumulatedDistance += segmentLength; pattern = 0xFFFF;
geode_->getOrCreateStateSet()->setAttributeAndModes(lineStippleState_.get(), osg::StateAttribute::OFF);
} else {
geode_->getOrCreateStateSet()->setAttributeAndModes(lineStippleState_.get(), osg::StateAttribute::ON);
}
lineStippleState_->setFactor(factor);
lineStippleState_->setPattern(pattern);
} }
drawArrays_->setCount(static_cast<GLsizei>(renderVertices_->size()));
} }

View File

@ -3,6 +3,7 @@
#include "entities/SceneComponent.h" #include "entities/SceneComponent.h"
#include <osg/Geometry> #include <osg/Geometry>
#include <osg/LineStipple>
#include <osg/LineWidth> #include <osg/LineWidth>
#include <osg/Vec4> #include <osg/Vec4>
#include <deque> #include <deque>
@ -70,18 +71,15 @@ private:
void AttachTraceToScene(); void AttachTraceToScene();
void TrimExpiredPoints(); void TrimExpiredPoints();
void UpdateStyle(); void UpdateStyle();
void DirtyGeometry();
void TrimOverflowPoints();
void RebuildRenderGeometry();
private: private:
osg::ref_ptr<osg::Geode> geode_; osg::ref_ptr<osg::Geode> geode_;
osg::ref_ptr<osg::Geometry> geometry_; osg::ref_ptr<osg::Geometry> geometry_;
osg::ref_ptr<osg::Vec3Array> vertices_; osg::ref_ptr<osg::Vec3Array> vertices_;
osg::ref_ptr<osg::Vec3Array> renderVertices_;
osg::ref_ptr<osg::Vec4Array> colors_; osg::ref_ptr<osg::Vec4Array> colors_;
osg::ref_ptr<osg::DrawArrays> drawArrays_; osg::ref_ptr<osg::DrawArrays> drawArrays_;
osg::ref_ptr<osg::LineWidth> lineWidthState_; osg::ref_ptr<osg::LineWidth> lineWidthState_;
osg::ref_ptr<osg::LineStipple> lineStippleState_;
osg::Vec4 color_{1.0f, 0.8f, 0.1f, 1.0f}; osg::Vec4 color_{1.0f, 0.8f, 0.1f, 1.0f};
float lineWidth_{2.0f}; float lineWidth_{2.0f};
@ -99,7 +97,6 @@ private:
double elapsedTime_{0.0}; double elapsedTime_{0.0};
osg::Vec3d lastSamplePos_{0.0, 0.0, 0.0}; osg::Vec3d lastSamplePos_{0.0, 0.0, 0.0};
bool hasLastSample_{false}; bool hasLastSample_{false};
bool traceRestartPending_{false};
bool attachedToScene_{false}; bool attachedToScene_{false};
std::deque<double> sampleTimes_; std::deque<double> sampleTimes_;
}; };

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -483,8 +483,7 @@ void QTrajectoryTraceComponentAttribute::SetColor(const QColor& c) {
} }
OsgUtils::QColorToVec4(c, &vColor); OsgUtils::QColorToVec4(c, &vColor);
const std::string value = StringUtils::Vec4ToString(vColor); object_->SetColor(vColor);
object_->SetAttribute("color", value.c_str());
} }
QColor QTrajectoryTraceComponentAttribute::GetColor() const { QColor QTrajectoryTraceComponentAttribute::GetColor() const {
@ -503,8 +502,7 @@ void QTrajectoryTraceComponentAttribute::SetLineWidth(double width) {
return; return;
} }
const std::string value = std::to_string(width); object_->SetLineWidth(static_cast<float>(width));
object_->SetAttribute("lineWidth", value.c_str());
} }
double QTrajectoryTraceComponentAttribute::GetLineWidth() const { double QTrajectoryTraceComponentAttribute::GetLineWidth() const {
@ -520,8 +518,7 @@ void QTrajectoryTraceComponentAttribute::SetSampleInterval(double interval) {
return; return;
} }
const std::string value = std::to_string(interval); object_->SetSampleInterval(interval);
object_->SetAttribute("sampleInterval", value.c_str());
} }
double QTrajectoryTraceComponentAttribute::GetSampleInterval() const { double QTrajectoryTraceComponentAttribute::GetSampleInterval() const {
@ -537,8 +534,7 @@ void QTrajectoryTraceComponentAttribute::SetMinMoveDistance(double distance) {
return; return;
} }
const std::string value = std::to_string(distance); object_->SetMinMoveDistance(distance);
object_->SetAttribute("minMoveDistance", value.c_str());
} }
double QTrajectoryTraceComponentAttribute::GetMinMoveDistance() const { double QTrajectoryTraceComponentAttribute::GetMinMoveDistance() const {
@ -554,8 +550,7 @@ void QTrajectoryTraceComponentAttribute::SetMaxPoints(int maxPoints) {
return; return;
} }
const std::string value = std::to_string(maxPoints); object_->SetMaxPoints(maxPoints);
object_->SetAttribute("maxPoints", value.c_str());
} }
int QTrajectoryTraceComponentAttribute::GetMaxPoints() const { int QTrajectoryTraceComponentAttribute::GetMaxPoints() const {
@ -571,8 +566,7 @@ void QTrajectoryTraceComponentAttribute::SetTailDuration(double duration) {
return; return;
} }
const std::string value = std::to_string(duration); object_->SetTailDuration(duration);
object_->SetAttribute("tailDuration", value.c_str());
} }
double QTrajectoryTraceComponentAttribute::GetTailDuration() const { double QTrajectoryTraceComponentAttribute::GetTailDuration() const {
@ -588,7 +582,7 @@ void QTrajectoryTraceComponentAttribute::SetVisible(bool visible) {
return; return;
} }
object_->SetAttribute("visible", visible ? "true" : "false"); object_->SetTraceVisible(visible);
} }
bool QTrajectoryTraceComponentAttribute::IsVisible() const { bool QTrajectoryTraceComponentAttribute::IsVisible() const {
@ -604,7 +598,7 @@ void QTrajectoryTraceComponentAttribute::SetDashed(bool dashed) {
return; return;
} }
object_->SetAttribute("dashed", dashed ? "true" : "false"); object_->SetDashed(dashed);
} }
bool QTrajectoryTraceComponentAttribute::IsDashed() const { bool QTrajectoryTraceComponentAttribute::IsDashed() const {
@ -620,8 +614,7 @@ void QTrajectoryTraceComponentAttribute::SetDashLength(double length) {
return; return;
} }
const std::string value = std::to_string(length); object_->SetDashLength(length);
object_->SetAttribute("dashLength", value.c_str());
} }
double QTrajectoryTraceComponentAttribute::GetDashLength() const { double QTrajectoryTraceComponentAttribute::GetDashLength() const {
@ -637,8 +630,7 @@ void QTrajectoryTraceComponentAttribute::SetGapLength(double length) {
return; return;
} }
const std::string value = std::to_string(length); object_->SetGapLength(length);
object_->SetAttribute("gapLength", value.c_str());
} }
double QTrajectoryTraceComponentAttribute::GetGapLength() const { double QTrajectoryTraceComponentAttribute::GetGapLength() const {
@ -654,8 +646,7 @@ void QTrajectoryTraceComponentAttribute::SetDashScrollSpeed(double speed) {
return; return;
} }
const std::string value = std::to_string(speed); object_->SetDashScrollSpeed(speed);
object_->SetAttribute("dashScrollSpeed", value.c_str());
} }
double QTrajectoryTraceComponentAttribute::GetDashScrollSpeed() const { double QTrajectoryTraceComponentAttribute::GetDashScrollSpeed() const {

View File

@ -23,6 +23,7 @@
#include "scene/OEScene.h" #include "scene/OEScene.h"
#include "workspace/WorkSpaceManager.h" #include "workspace/WorkSpaceManager.h"
#include "workspace/WorkSpace.h" #include "workspace/WorkSpace.h"
//#include "scutcheon/osgScutcheon.h"
#include "workspace/PresetModelConfigParser.h" #include "workspace/PresetModelConfigParser.h"
#include "entities/EntitiesManager.h" #include "entities/EntitiesManager.h"