MCPcopy Create free account
hub / github.com/GollyGang/ready / SetValuesInRadius

Method SetValuesInRadius

src/readybase/ImageRD.cpp:1617–1678  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1615// --------------------------------------------------------------------------------
1616
1617void ImageRD::SetValuesInRadius(float x,float y,float z,float r,float val,const Properties& render_settings)
1618{
1619 const int X = this->GetX();
1620 const int Y = this->GetY();
1621 const int Z = this->GetZ();
1622
1623 // which chemical was clicked-on?
1624 float offset_x = 0.0f;
1625 bool show_multiple_chemicals = render_settings.GetProperty("show_multiple_chemicals").GetBool();
1626 int iChemical;
1627 if(show_multiple_chemicals && this->GetArenaDimensionality()==1)
1628 {
1629 // detect which chemical was drawn on from the click position
1630 const double image_height = X / this->image_ratio1D;
1631 iChemical = int(floor((- y + this->image_top1D + image_height)/(image_height*2)));
1632 iChemical = min(this->GetNumberOfChemicals()-1,max(0,iChemical)); // clamp to allowed range (just in case)
1633 }
1634 else if(show_multiple_chemicals && this->GetArenaDimensionality()>=2)
1635 {
1636 // detect which chemical was drawn on from the click position
1637 const float x_gap = this->x_spacing_proportion * this->GetX();
1638 iChemical = int(floor((x + x_gap / 2) / (X + x_gap)));
1639 iChemical = min(this->GetNumberOfChemicals()-1,max(0,iChemical)); // clamp to allowed range (just in case)
1640 offset_x = iChemical * (X + x_gap);
1641 }
1642 else
1643 {
1644 // only one chemical is shown, must be that one
1645 iChemical = IndexFromChemicalName(render_settings.GetProperty("active_chemical").GetChemical());
1646 }
1647
1648 double *dataset_bbox = this->images.front()->GetBounds();
1649 r *= hypot3(dataset_bbox[1]-dataset_bbox[0],dataset_bbox[3]-dataset_bbox[2],dataset_bbox[5]-dataset_bbox[4]);
1650
1651 int ix,iy,iz;
1652 ix = int(floor(x-offset_x));
1653 iy = int(floor(y));
1654 iz = int(floor(z));
1655 ix = min(X-1,max(0,ix));
1656 iy = min(Y-1,max(0,iy));
1657 iz = min(Z-1,max(0,iz));
1658
1659 for(int tz=max(0,int(iz-r));tz<=min(Z-1,int(iz+r));tz++)
1660 {
1661 for(int ty=max(0,int(iy-r));ty<=min(Y-1,int(iy+r));ty++)
1662 {
1663 for(int tx=max(0,int(ix-r));tx<=min(X-1,int(ix+r));tx++)
1664 {
1665 if(hypot3(ix-tx,iy-ty,iz-tz)<r)
1666 {
1667 float old_val = this->GetImage(iChemical)->GetScalarComponentAsFloat(tx,ty,tz,0);
1668 int ijk[3] = { tx, ty, tz };
1669 vtkIdType iCell = this->GetImage(iChemical)->ComputeCellId(ijk);
1670 this->StorePaintAction(iChemical,iCell,old_val);
1671 this->GetImage(iChemical)->SetScalarComponentFromFloat(tx,ty,tz,0,val);
1672 }
1673 }
1674 }

Callers

nothing calls this directly

Calls 10

GetXMethod · 0.95
GetYMethod · 0.95
GetZMethod · 0.95
GetImageMethod · 0.95
IndexFromChemicalNameFunction · 0.85
hypot3Function · 0.85
GetBoolMethod · 0.80
GetNumberOfChemicalsMethod · 0.80
StorePaintActionMethod · 0.80

Tested by

no test coverage detected