Skip to content

Commit b8ad41d

Browse files
Reframe render objects when showing or hiding axons
1 parent a2113b4 commit b8ad41d

File tree

5 files changed

+63
-34
lines changed

5 files changed

+63
-34
lines changed

src/EMRenderer.cpp

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace
1919
float maxHeight = std::numeric_limits<float>::min();
2020
for (int i = 0; i < cellRenderObjects.size(); i++)
2121
{
22-
CellMorphology::Extent extent = cellRenderObjects[i]->morphologyObject.ComputeExtents();
22+
CellMorphology::Extent extent = cellRenderObjects[i]->morphologyObject.totalExtent;
2323
mv::Vector3f dimensions = extent.emax - extent.emin;
2424

2525
if (dimensions.y > maxHeight)
@@ -56,11 +56,8 @@ void EMRenderer::resize(int w, int h)
5656
float aspectRatio = (float)w / h;
5757
qDebug() << "Resize called";
5858
_projMatrix.setToIdentity();
59-
//_projMatrix.ortho(0, aspectRatio, 0, 1, -1, 1);
60-
6159
_projMatrix.ortho(0, aspectRatio, 0, 1, 1, -1);
6260

63-
vx = 0; vy = 0; vw = w; vh = h;
6461
_fullViewport.Set(0, 0, w, h);
6562

6663
int quarter = h / 4;
@@ -105,7 +102,7 @@ void EMRenderer::update(float t)
105102
_morphologyViewport.Begin();
106103
_projMatrix.setToIdentity();
107104
_projMatrix.ortho(0, _morphologyViewport.GetAspectRatio(), 0, 1, -1, 1);
108-
qDebug() << "Aspect ratio: " << _morphologyViewport.GetAspectRatio();
105+
109106
_lineShader.uniformMatrix4f("projMatrix", _projMatrix.constData());
110107

111108
float xOffset = 0;
@@ -114,12 +111,17 @@ void EMRenderer::update(float t)
114111
//if (cortical)
115112
// yToUnit = MapYRangeToUnit(-_scene.getCortexStructure().getMaxDepth(), -_scene.getCortexStructure().getMinDepth());
116113

114+
std::vector<CellMorphology::Type> ignoredTypes;
115+
if (!_showAxons)
116+
ignoredTypes.push_back(CellMorphology::Type::Axon);
117+
117118
//qDebug() << "Rendering " << cellRenderObjects.size() << " objects.";
118119
for (int i = 0; i < cellRenderObjects.size(); i++)
119120
{
120121
CellRenderObject* cro = cellRenderObjects[i];
121122

122-
CellMorphology::Extent extent = cro->morphologyObject.ComputeExtents();
123+
cro->morphologyObject.ComputeExtents(ignoredTypes);
124+
const CellMorphology::Extent& extent = cro->morphologyObject.totalExtent;
123125

124126
mv::Vector3f dimensions = extent.emax - extent.emin;
125127

@@ -150,6 +152,8 @@ void EMRenderer::update(float t)
150152
for (auto it = cro->morphologyObject.processes.begin(); it != cro->morphologyObject.processes.end(); ++it)
151153
{
152154
CellMorphology::Type type = it.key();
155+
if (type == CellMorphology::Type::Axon && !_showAxons)
156+
continue;
153157
MorphologyProcessRenderObject mpro = it.value();
154158
_lineShader.uniform1i("type", (int)type);
155159
glBindVertexArray(mpro.vao);
@@ -179,7 +183,7 @@ void EMRenderer::update(float t)
179183
{
180184
CellRenderObject* cro = cellRenderObjects[i];
181185

182-
CellMorphology::Extent extent = cro->morphologyObject.ComputeExtents();
186+
const CellMorphology::Extent& extent = cro->morphologyObject.totalExtent;
183187
mv::Vector3f dimensions = extent.emax - extent.emin;
184188
float maxWidth = sqrtf(powf(dimensions.x, 2) + powf(dimensions.z, 2)) * 1.5f;
185189

@@ -246,6 +250,8 @@ void EMRenderer::showAxons(bool enabled)
246250
_showAxons = enabled;
247251

248252
//RebuildMorphologies();
253+
254+
RequestNewWidgetWidth();
249255
}
250256

251257
void EMRenderer::setCurrentStimset(const QString& stimSet)
@@ -262,20 +268,9 @@ void EMRenderer::SetCortical(bool isCortical)
262268

263269
void EMRenderer::SetSelectedCellIds(const std::vector<Cell>& cells)
264270
{
265-
std::vector<QString> cellIds;
266-
267271
// Build list of selected cell render object references
268272
std::vector<CellRenderObject*> cellRenderObjects;
269-
for (const Cell& cell : cells)
270-
{
271-
cellIds.push_back(cell.cellId);
272-
auto it = _renderState._cellRenderObjects.find(cell.cellId);
273-
274-
if (it != _renderState._cellRenderObjects.end())
275-
cellRenderObjects.push_back(&(*it));
276-
else
277-
qDebug() << "[EMRenderer] This should never happen, but cellId wasn't found in _cellRenderObjects";
278-
}
273+
BuildListOfCellRenderObjects(cells, cellRenderObjects);
279274

280275
_renderState._selectedCells = cells;
281276

@@ -313,13 +308,45 @@ void EMRenderer::SetSelectedCellIds(const std::vector<Cell>& cells)
313308
}
314309
}
315310

311+
RequestNewWidgetWidth();
312+
}
313+
314+
void EMRenderer::BuildRenderObjects(const std::vector<Cell>& cells)
315+
{
316+
_renderObjectBuilder.BuildCellRenderObjects(cells);
317+
}
318+
319+
void EMRenderer::BuildListOfCellRenderObjects(const std::vector<Cell>& cells, std::vector<CellRenderObject*>& cellRenderObjects)
320+
{
321+
// Build list of selected cell render object references
322+
for (const Cell& cell : cells)
323+
{
324+
auto it = _renderState._cellRenderObjects.find(cell.cellId);
325+
326+
if (it != _renderState._cellRenderObjects.end())
327+
cellRenderObjects.push_back(&(*it));
328+
else
329+
qDebug() << "[EMRenderer] This should never happen, but cellId wasn't found in _cellRenderObjects";
330+
}
331+
}
332+
333+
void EMRenderer::RequestNewWidgetWidth()
334+
{
335+
std::vector<CellRenderObject*> cellRenderObjects;
336+
BuildListOfCellRenderObjects(_renderState._selectedCells, cellRenderObjects);
337+
338+
std::vector<CellMorphology::Type> ignoredTypes;
339+
if (!_showAxons)
340+
ignoredTypes.push_back(CellMorphology::Type::Axon);
341+
316342
// Compute new widget width
317343
float newWidgetWidthToRequest = 0;
318344
for (int i = 0; i < cellRenderObjects.size(); i++)
319345
{
320-
CellMorphology::Extent extent = cellRenderObjects[i]->morphologyObject.ComputeExtents();
346+
cellRenderObjects[i]->morphologyObject.ComputeExtents(ignoredTypes);
347+
CellMorphology::Extent extent = cellRenderObjects[i]->morphologyObject.totalExtent;
321348
mv::Vector3f dimensions = extent.emax - extent.emin;
322-
349+
323350
newWidgetWidthToRequest += sqrtf(powf(dimensions.x, 2) + powf(dimensions.z, 2)) * 1.2f;
324351
}
325352

@@ -330,8 +357,3 @@ void EMRenderer::SetSelectedCellIds(const std::vector<Cell>& cells)
330357

331358
emit requestNewAspectRatio(aspectRatioRequest);
332359
}
333-
334-
void EMRenderer::BuildRenderObjects(const std::vector<Cell>& cells)
335-
{
336-
_renderObjectBuilder.BuildCellRenderObjects(cells);
337-
}

src/EMRenderer.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ class EMRenderer : public QObject, protected QOpenGLFunctions_3_3_Core
3939
void showAxons(bool enabled);
4040
void setCurrentStimset(const QString& stimset);
4141

42+
private:
43+
void BuildListOfCellRenderObjects(const std::vector<Cell>& cells, std::vector<CellRenderObject*>& cellRenderObjects);
44+
void RequestNewWidgetWidth();
45+
4246
signals:
4347
void requestNewAspectRatio(float aspectRatio);
4448

@@ -55,7 +59,6 @@ class EMRenderer : public QObject, protected QOpenGLFunctions_3_3_Core
5559

5660
bool _isCortical = false;
5761

58-
int vx, vy, vw, vh;
5962
RenderRegion _fullViewport;
6063
RenderRegion _morphologyViewport;
6164
RenderRegion _traceViewport;

src/MEWidget.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ void MEWidget::onWidgetInitialized()
5151
{
5252
_emRenderer.init();
5353

54-
// Start 50 fps render timer
54+
// Start 40 fps render timer
5555
QTimer* updateTimer = new QTimer();
5656
QObject::connect(updateTimer, &QTimer::timeout, this, [this]() { update(); });
57-
updateTimer->start(1000.0f / 50);
57+
updateTimer->start(1000.0f / 40);
5858
}
5959

6060
void MEWidget::onWidgetResized(int w, int h)

src/Rendering/CellRenderObject.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@ void CellRenderObject::Cleanup(QOpenGLFunctions_3_3_Core* f)
1414
//f->glDeleteVertexArrays(1, &acquisitionObject.vao);
1515
}
1616

17-
CellMorphology::Extent MorphologyRenderObject::ComputeExtents()
17+
void MorphologyRenderObject::ComputeExtents(std::vector<CellMorphology::Type> ignoredTypes)
1818
{
19-
CellMorphology::Extent totalExtent;
2019
totalExtent.emin = mv::Vector3f(std::numeric_limits<float>::max());
2120
totalExtent.emax = mv::Vector3f(-std::numeric_limits<float>::max());
2221

2322
for (auto it = processes.constBegin(); it != processes.constEnd(); ++it)
24-
totalExtent.Extend(it.value().extents);
23+
{
24+
if (std::find(ignoredTypes.begin(), ignoredTypes.end(), it.key()) != ignoredTypes.end())
25+
continue;
2526

26-
return totalExtent;
27+
totalExtent.Extend(it.value().extents);
28+
}
2729
}

src/Rendering/CellRenderObject.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ struct MorphologyProcessRenderObject
2626
class MorphologyRenderObject
2727
{
2828
public:
29-
CellMorphology::Extent ComputeExtents();
29+
void ComputeExtents(std::vector<CellMorphology::Type> ignoredTypes);
3030

3131
QHash<CellMorphology::Type, MorphologyProcessRenderObject> processes;
3232

3333
mv::Vector3f somaPosition;
3434
float somaRadius;
3535

36+
CellMorphology::Extent totalExtent;
37+
3638
///* Centerpoint of the morphology, around which it will rotate */
3739
//mv::Vector3f _anchorPoint;
3840
};

0 commit comments

Comments
 (0)