mirror of
https://github.com/NGSolve/netgen.git
synced 2025-01-12 22:20:35 +05:00
Merge branch 'function_value_on_dblclick' into 'master'
Print function value on double click See merge request jschoeberl/netgen!361
This commit is contained in:
commit
8d1bbd5b50
@ -209,6 +209,8 @@ namespace netgen
|
||||
void BuildBadelList();
|
||||
void BuildIdentifiedList();
|
||||
void BuildDomainSurfList();
|
||||
|
||||
bool Unproject (int px, int py, Point<3> &p);
|
||||
};
|
||||
|
||||
DLL_HEADER extern VisualSceneMesh vsmesh;
|
||||
|
@ -3128,9 +3128,7 @@ namespace netgen
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void VisualSceneMesh :: MouseDblClick (int px, int py)
|
||||
bool VisualSceneMesh :: Unproject (int px, int py, Point<3> &p)
|
||||
{
|
||||
shared_ptr<Mesh> mesh = GetMesh();
|
||||
|
||||
@ -3150,20 +3148,63 @@ namespace netgen
|
||||
int hy = viewport[3]-py;
|
||||
|
||||
GLfloat pz;
|
||||
|
||||
if(lock)
|
||||
{
|
||||
lock->UnLock();
|
||||
delete lock;
|
||||
lock = NULL;
|
||||
}
|
||||
|
||||
// cout << "x, y = " << px << ", " << hy << endl;
|
||||
glReadPixels (px, hy, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &pz);
|
||||
|
||||
if(pz>=1.0)
|
||||
return false;
|
||||
if(pz<=0.0)
|
||||
return false;
|
||||
|
||||
// cout << "pz = " << pz << endl;
|
||||
gluUnProject(px, hy, pz, transformationmat, projection, viewport,
|
||||
&result[0], &result[1], &result[2]);
|
||||
|
||||
if (pz < 1.0)
|
||||
cout << "point : " << result[0] << ", " << result[1] << ", " << result[2] << endl;
|
||||
|
||||
p = Point<3>{result[0], result[1], result[2]};
|
||||
return true;
|
||||
}
|
||||
|
||||
if (user_me_handler && pz < 1.0)
|
||||
|
||||
void VisualSceneMesh :: MouseDblClick (int px, int py)
|
||||
{
|
||||
Point<3> p;
|
||||
bool found_point = Unproject(px, py, p);
|
||||
|
||||
if(selelement!=-1)
|
||||
{
|
||||
if (selelement != -1)
|
||||
user_me_handler -> DblClick (selelement-1, result[0], result[1], result[2]);
|
||||
const Element2d & sel = GetMesh()->SurfaceElement(selelement);
|
||||
|
||||
cout << "select element " << selelement
|
||||
<< " on face " << sel.GetIndex() << endl;
|
||||
cout << "Nodes: ";
|
||||
for (int i = 1; i <= sel.GetNP(); i++)
|
||||
cout << sel.PNum(i) << " ";
|
||||
cout << endl;
|
||||
|
||||
cout << "selected point " << selpoint
|
||||
<< ", pos = " << GetMesh()->Point (selpoint)
|
||||
<< endl;
|
||||
|
||||
cout << "seledge = " << seledge << endl;
|
||||
|
||||
}
|
||||
|
||||
if(found_point)
|
||||
{
|
||||
cout << "point : " << p << endl;
|
||||
if (user_me_handler)
|
||||
{
|
||||
if (selelement != -1)
|
||||
user_me_handler -> DblClick (selelement-1, p[0], p[1], p[2]);
|
||||
}
|
||||
}
|
||||
|
||||
selecttimestamp = NextTimeStamp();
|
||||
@ -3401,6 +3442,7 @@ namespace netgen
|
||||
|
||||
if (vispar.clipping.enable)
|
||||
{
|
||||
glEnable(GL_CLIP_PLANE0);
|
||||
Vec<3> n(clipplane[0], clipplane[1], clipplane[2]);
|
||||
double len = Abs(n);
|
||||
double mu = -clipplane[3] / (len*len);
|
||||
@ -3473,23 +3515,12 @@ namespace netgen
|
||||
{
|
||||
const Element2d & sel = mesh->SurfaceElement(minname);
|
||||
|
||||
|
||||
cout << "select element " << minname
|
||||
<< " on face " << sel.GetIndex() << endl;
|
||||
cout << "Nodes: ";
|
||||
for (i = 1; i <= sel.GetNP(); i++)
|
||||
cout << sel.PNum(i) << " ";
|
||||
cout << endl;
|
||||
|
||||
selelement = minname;
|
||||
selface = mesh->SurfaceElement(minname).GetIndex();
|
||||
|
||||
locpi = (locpi % sel.GetNP()) + 1;
|
||||
selpoint2 = selpoint;
|
||||
selpoint = sel.PNum(locpi);
|
||||
cout << "selected point " << selpoint
|
||||
<< ", pos = " << mesh->Point (selpoint)
|
||||
<< endl;
|
||||
|
||||
for (i = 1; i <= mesh->GetNSeg(); i++)
|
||||
{
|
||||
@ -3498,7 +3529,6 @@ namespace netgen
|
||||
(seg[1] == selpoint && seg[0] == selpoint2) )
|
||||
{
|
||||
seledge = seg.edgenr;
|
||||
cout << "seledge = " << seledge << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4754,9 +4754,166 @@ namespace netgen
|
||||
|
||||
void VisualSceneSolution :: MouseDblClick (int px, int py)
|
||||
{
|
||||
vsmesh.SetClippingPlane();
|
||||
// vsmesh.BuildFilledList();
|
||||
vsmesh.MouseDblClick(px,py);
|
||||
auto mesh = GetMesh();
|
||||
auto dim = mesh->GetDimension();
|
||||
|
||||
auto formatComplex = [](double real, double imag)
|
||||
{
|
||||
return ToString(real) + (imag < 0 ? "" : "+") + ToString(imag) + "j";
|
||||
};
|
||||
|
||||
auto printScalValue = [&formatComplex]
|
||||
(SolData & sol, int comp, double value, double imag=0., bool iscomplex=false)
|
||||
{
|
||||
if(sol.components>1)
|
||||
{
|
||||
if(comp==0)
|
||||
cout << "func(" << sol.name << ")";
|
||||
else
|
||||
cout << sol.name << "["+ToString(comp)+"]";
|
||||
}
|
||||
else
|
||||
cout << sol.name;
|
||||
cout << " = " << (iscomplex ? formatComplex(value, imag) : ToString(value)) << endl;
|
||||
};
|
||||
|
||||
auto printVecValue = [&formatComplex]
|
||||
(SolData & sol, FlatArray<double> values)
|
||||
{
|
||||
if(sol.iscomplex)
|
||||
{
|
||||
cout << sol.name << " = ( " << formatComplex(values[0], values[1]);
|
||||
for(int i = 2; i < values.Size(); i+=2)
|
||||
cout << ", " << formatComplex(values[i], values[i+1]);
|
||||
cout << " )" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << sol.name << " = ( " << values[0];
|
||||
for(int i = 1; i < values.Size(); i++)
|
||||
cout << ", " << values[i];
|
||||
cout << " )" << endl;
|
||||
}
|
||||
};
|
||||
|
||||
// Check if clipping plane is drawn at current mouse cursor position
|
||||
if(dim==3 && clipsolution && vispar.clipping.enable)
|
||||
{
|
||||
GLint viewport[4];
|
||||
GLdouble projection[16];
|
||||
glGetDoublev(GL_PROJECTION_MATRIX, &projection[0]);
|
||||
|
||||
glGetIntegerv(GL_VIEWPORT, &viewport[0]);
|
||||
|
||||
int hy = viewport[3]-py;
|
||||
|
||||
// manually intersect the view vector with the clipping plane (also working if clipping vectors are shown)
|
||||
Point<3> p_clipping_plane;
|
||||
gluUnProject(px, hy, 1.0, transformationmat, projection, viewport,
|
||||
&p_clipping_plane[0], &p_clipping_plane[1], &p_clipping_plane[2]);
|
||||
|
||||
Point<3> eye;
|
||||
gluUnProject( (viewport[2]-viewport[0])/2 , (viewport[3]-viewport[1])/2,
|
||||
0.0, transformationmat, projection, viewport, &eye[0], &eye[1], &eye[2]);
|
||||
|
||||
Vec<3> n{vispar.clipping.normal};
|
||||
n.Normalize();
|
||||
Vec<3> view = p_clipping_plane-eye;
|
||||
|
||||
// check if we look at the clipping plane from the right direction
|
||||
if(n*view > 1e-8)
|
||||
{
|
||||
double lam = vispar.clipping.dist - Vec<3>{eye}*n;
|
||||
lam /= n*view;
|
||||
p_clipping_plane = eye + lam*view;
|
||||
|
||||
double lami[3];
|
||||
if(auto el3d = mesh->GetElementOfPoint( p_clipping_plane, lami ))
|
||||
{
|
||||
cout << endl << "Selected point " << p_clipping_plane << " on clipping plane" << endl;
|
||||
|
||||
bool have_scal_func = scalfunction!=-1 && soldata[scalfunction]->draw_volume;
|
||||
bool have_vec_func = vecfunction!=-1 && soldata[vecfunction]->draw_volume;
|
||||
|
||||
if(have_scal_func)
|
||||
{
|
||||
auto & sol = *soldata[scalfunction];
|
||||
double val;
|
||||
double imag = 0;
|
||||
int rcomponent = scalcomp;
|
||||
int comp = scalcomp;
|
||||
if(sol.iscomplex && rcomponent != 0)
|
||||
{
|
||||
rcomponent = 2 * ((rcomponent-1)/2) + 1;
|
||||
GetValue(&sol, el3d-1, lami[0], lami[1], lami[2], rcomponent+1,
|
||||
imag);
|
||||
comp = (scalcomp-1)/2 + 1;
|
||||
}
|
||||
GetValue(&sol, el3d-1, lami[0], lami[1], lami[2], rcomponent, val);
|
||||
printScalValue(sol, comp, val, imag, sol.iscomplex && comp > 0);
|
||||
}
|
||||
if(vecfunction!=-1 && soldata[vecfunction]->draw_volume)
|
||||
{
|
||||
auto & sol = *soldata[vecfunction];
|
||||
ArrayMem<double, 10> values(sol.components);
|
||||
GetValues(&sol, el3d-1, lami[0], lami[1], lami[2], &values[0]);
|
||||
printVecValue(sol, values);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// no point on clipping plane found -> continue searching for surface element
|
||||
|
||||
Point<3> p;
|
||||
bool found_point = vsmesh.Unproject(px, py, p);
|
||||
if(!found_point)
|
||||
return;
|
||||
|
||||
if(selelement==0)
|
||||
return;
|
||||
|
||||
double lami[3] = {0.0, 0.0, 0.0};
|
||||
// Check if unprojected Point is close to surface element (eps of 1e-3 due to z-Buffer accuracy)
|
||||
bool found_2del = false;
|
||||
if(mesh->PointContainedIn2DElement(p, lami, selelement, false && fabs(lami[2])<1e-3))
|
||||
{
|
||||
// Found it, use coordinates of point projected to surface element
|
||||
mesh->GetCurvedElements().CalcSurfaceTransformation({1.0-lami[0]-lami[1], lami[0]}, selelement-1, p);
|
||||
found_2del = true;
|
||||
}
|
||||
cout << endl << "Selected point " << p << " on surface" << endl;
|
||||
|
||||
if(!found_2del)
|
||||
return;
|
||||
|
||||
bool have_scal_func = scalfunction!=-1 && soldata[scalfunction]->draw_surface;
|
||||
bool have_vec_func = vecfunction!=-1 && soldata[vecfunction]->draw_surface;
|
||||
|
||||
if(have_scal_func)
|
||||
{
|
||||
auto & sol = *soldata[scalfunction];
|
||||
double val;
|
||||
double imag = 0;
|
||||
int rcomponent = scalcomp;
|
||||
int comp = scalcomp;
|
||||
if(sol.iscomplex && rcomponent != 0)
|
||||
{
|
||||
rcomponent = 2 * ((rcomponent-1)/2) + 1;
|
||||
GetSurfValue(&sol, selelement-1, -1, 1.0-lami[0]-lami[1], lami[0], rcomponent+1, imag);
|
||||
comp = (scalcomp-1)/2 + 1;
|
||||
}
|
||||
GetSurfValue(&sol, selelement-1, -1, 1.0-lami[0]-lami[1], lami[0], rcomponent, val);
|
||||
printScalValue(sol, comp, val, imag, sol.iscomplex && comp > 0);
|
||||
}
|
||||
if(have_vec_func)
|
||||
{
|
||||
auto & sol = *soldata[vecfunction];
|
||||
ArrayMem<double, 10> values(sol.components);
|
||||
GetSurfValues(&sol, selelement-1, -1, 1.0-lami[0]-lami[1], lami[0], &values[0]);
|
||||
printVecValue(sol, values);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user