Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 37 additions & 26 deletions lib/aux_js.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ using namespace mfem;
// display a new stream
// field_type: 0 - scalar data, 1 - vector data, 2 - mesh only, (-1) - unknown
//
int display(const int field_type, std::stringstream & commands, const int w,
const int h)
StreamState::FieldType display(const StreamState::FieldType field_type,
std::stringstream & commands,
const int w,
const int h)
{
// reset antialiasing
GetAppWindow()->getRenderer().setAntialiasing(0);
Expand All @@ -74,21 +76,24 @@ int display(const int field_type, std::stringstream & commands, const int w,
}
}

if (field_type < 0 || field_type > 2)
// If unknown, default to vector field_type
if (field_type <= StreamState::FieldType::MIN
|| field_type >= StreamState::FieldType::MAX)
{
return 1;
return StreamState::FieldType::VECTOR;
}

if (InitVisualization("glvis", 0, 0, w, h))
{
return 1;
return StreamState::FieldType::VECTOR;
}

delete vs;
vs = nullptr;

double mesh_range = -1.0;
if (field_type == 0 || field_type == 2)
if (field_type == StreamState::FieldType::SCALAR
|| field_type == StreamState::FieldType::MESH)
{
if (stream_state.grid_f)
{
Expand All @@ -100,17 +105,18 @@ int display(const int field_type, std::stringstream & commands, const int w,
if (stream_state.normals.Size() > 0)
{
vs = vss = new VisualizationSceneSolution(*stream_state.mesh, stream_state.sol,
&stream_state.normals);
stream_state.mesh_quad.get(), &stream_state.normals);
}
else
{
vs = vss = new VisualizationSceneSolution(*stream_state.mesh, stream_state.sol);
vs = vss = new VisualizationSceneSolution(*stream_state.mesh, stream_state.sol,
stream_state.mesh_quad.get());
}
if (stream_state.grid_f)
{
vss->SetGridFunction(*stream_state.grid_f);
}
if (field_type == 2)
if (field_type == StreamState::FieldType::MESH)
{
vs->OrthogonalProjection = 1;
vs->SetLight(0);
Expand All @@ -124,12 +130,12 @@ int display(const int field_type, std::stringstream & commands, const int w,
{
VisualizationSceneSolution3d * vss;
vs = vss = new VisualizationSceneSolution3d(*stream_state.mesh,
stream_state.sol);
stream_state.sol, stream_state.mesh_quad.get());
if (stream_state.grid_f)
{
vss->SetGridFunction(stream_state.grid_f.get());
}
if (field_type == 2)
if (field_type == StreamState::FieldType::MESH)
{
if (stream_state.mesh->Dimension() == 3)
{
Expand All @@ -150,7 +156,7 @@ int display(const int field_type, std::stringstream & commands, const int w,
vss->ToggleDrawMesh();
}
}
if (field_type == 2)
if (field_type == StreamState::FieldType::MESH)
{
if (stream_state.grid_f)
{
Expand All @@ -162,7 +168,7 @@ int display(const int field_type, std::stringstream & commands, const int w,
}
}
}
else if (field_type == 1)
else if (field_type == StreamState::FieldType::VECTOR)
{
if (stream_state.mesh->SpaceDimension() == 2)
{
Expand All @@ -180,8 +186,7 @@ int display(const int field_type, std::stringstream & commands, const int w,
{
if (stream_state.grid_f)
{
stream_state.grid_f
= ProjectVectorFEGridFunction(std::move(stream_state.grid_f));
stream_state.ProjectVectorFEGridFunction();
vs = new VisualizationSceneVector3d(*stream_state.grid_f);
}
else
Expand All @@ -198,14 +203,15 @@ int display(const int field_type, std::stringstream & commands, const int w,
if (stream_state.grid_f)
{
vs->AutoRefine();
vs->SetShading(2, true);
vs->SetShading(VisualizationSceneScalarData::Shading::Noncomforming, true);
}
if (mesh_range > 0.0)
{
vs->SetValueRange(-mesh_range, mesh_range);
vs->SetAutoscale(0);
}
if (stream_state.mesh->SpaceDimension() == 2 && field_type == 2)
if (stream_state.mesh->SpaceDimension() == 2 &&
field_type == StreamState::FieldType::MESH)
{
SetVisualizationScene(vs, 2);
}
Expand All @@ -223,7 +229,7 @@ int display(const int field_type, std::stringstream & commands, const int w,
}

SendExposeEvent();
return 0;
return StreamState::FieldType::SCALAR;
}

//
Expand All @@ -234,8 +240,9 @@ int display(const int field_type, std::stringstream & commands, const int w,
// each string in streams must start with `parallel <nproc> <rank>'
//
using StringArray = std::vector<std::string>;
int processParallelStreams(StreamState & state, const StringArray & streams,
std::stringstream * commands = nullptr)
StreamState::FieldType processParallelStreams(StreamState & state,
const StringArray & streams,
std::stringstream * commands = nullptr)
{
// std::cerr << "got " << streams.size() << " streams" << std::endl;
// HACK: match unique_ptr<istream> interface for ReadStreams:
Expand All @@ -252,7 +259,7 @@ int processParallelStreams(StreamState & state, const StringArray & streams,
istreams[i] = std::unique_ptr<std::istream>(&sstreams[i]);
}

const int field_type = state.ReadStreams(istreams);
const StreamState::FieldType field_type = state.ReadStreams(istreams);

if (commands)
{
Expand All @@ -270,20 +277,24 @@ int processParallelStreams(StreamState & state, const StringArray & streams,
return field_type;
}

int displayParallelStreams(const StringArray & streams, const int w,
const int h)
StreamState::FieldType displayParallelStreams(const StringArray & streams,
const int w,
const int h)
{
std::stringstream commands(streams[0]);
const int field_type = processParallelStreams(stream_state, streams, &commands);
const StreamState::FieldType field_type = processParallelStreams(stream_state,
streams, &commands);
return display(field_type, commands, w, h);
}

int displayStream(const std::string & stream, const int w, const int h)
StreamState::FieldType displayStream(const std::string & stream, const int w,
const int h)
{
std::stringstream ss(stream);
std::string data_type;
ss >> data_type;
const int field_type = stream_state.ReadStream(ss, data_type);
const StreamState::FieldType field_type = stream_state.ReadStream(ss,
data_type);

return display(field_type, ss, w, h);
}
Expand Down