All pastes #814234 Raw Edit

Zeug

public cpp v1 · immutable
·published 2007-12-13 02:57 UTC
rendered paste body
	class Cell {	public:		Cell(const UTriple& center_label, const UTriple& center_grid, bool complete)			: mCenter_label(center_label),			  mCenter_grid(center_grid),			  mActiveLabelCount(0),			  mComplete(complete),			  mRemoved(false),			  mQueued(false) {		}				const UTriple mCenter_label;		const UTriple mCenter_grid;		uint mActiveLabelCount;		uchar mComplete : 1,			  mRemoved : 1,			  mQueued : 1;	};		// build grid	uint radius = 2; // voxels	uint distance = 2; // cells	QVector<Cell*> grid;	UTriple labels_size(xs, ys, zs);	UTriple label_root;	UTriple grid_offset;	UTriple grid_root;	UTriple grid_size;		foreach (Marker* marker, container->mVolume->mMarkers) {		if (!marker->isActive())			continue;				label_root = marker->position();		break;	}		if (   label_root[0] < radius	    || label_root[1] < radius	    || label_root[2] < radius	    || label_root[0] + radius >= labels_size[0]	    || label_root[1] + radius >= labels_size[1]	    || label_root[2] + radius >= labels_size[2]) {		qWarning("GrowingCoronarySegmentation execute: Marker %s to near to a border",		         qPrintable(label_root.toString()));		return;	}		grid_offset[0] = label_root[0] % (radius * 2 + 1);	grid_offset[1] = label_root[1] % (radius * 2 + 1);	grid_offset[2] = label_root[2] % (radius * 2 + 1);		grid_root[0] = (label_root[0] - grid_offset[0]) / (radius * 2 + 1);	grid_root[1] = (label_root[1] - grid_offset[1]) / (radius * 2 + 1);	grid_root[2] = (label_root[2] - grid_offset[2]) / (radius * 2 + 1);		grid_size[0] = (uint)floor((float)(labels_size[0] - (grid_offset[0] - radius)) / (float)(radius * 2 + 1));	grid_size[1] = (uint)floor((float)(labels_size[1] - (grid_offset[1] - radius)) / (float)(radius * 2 + 1));	grid_size[2] = (uint)floor((float)(labels_size[2] - (grid_offset[2] - radius)) / (float)(radius * 2 + 1));		qDebug("label_root %s", qPrintable(label_root.toString()));	qDebug("labels_size %s", qPrintable(labels_size.toString()));	qDebug("grid_offset %s", qPrintable(grid_offset.toString()));	qDebug("grid_root %s", qPrintable(grid_root.toString()));	qDebug("grid_size %s", qPrintable(grid_size.toString()));		UTriple backup_labels_size = labels_size;	UTriple backup_label_root = label_root;	UTriple backup_grid_offset = grid_offset;	UTriple backup_grid_root = grid_root;	UTriple backup_grid_size = grid_size;	/*	QQueue<UTriple> wallqueue;		if (label_root[2] >= (radius * 2 + 1) * distance)		wallqueue << label_root.translated<int>(0, 0, -(int)((radius * 2 + 1) * distance));		if (labels_size[2] - label_root[2] >= (radius * 2 + 1) * distance)		wallqueue << label_root.translated<int>(0, 0, +(int)((radius * 2 + 1) * distance));		while (!wallqueue.isEmpty()) {		const UTriple label = wallqueue.dequeue();				for (int k = 0; k < 6; ++k) {			const int ldx = neighborhood_direct[k][0];			const int ldy = neighborhood_direct[k][1];			const int ldz = neighborhood_direct[k][2];						if (ldz != 0)				continue;						if (ldx < 0 && label[0] <= 0)				continue;						if (ldx > 0 && label[0] >= labels_size[0] - 1)				continue;						if (ldy < 0 && label[1] <= 0)				continue;						if (ldy > 0 && label[1] >= labels_size[1] - 1)				continue;						if (ldz < 0 && label[2] <= 0)				continue;						if (ldz > 0 && label[2] >= labels_size[2] - 1)				continue;						const UTriple neighbor_label = label.translated<int>(ldx, ldy, ldz);						if (labels[neighbor_label.linearized(labels_size)] == LabelGroup::Grown) {				labels[neighbor_label.linearized(labels_size)] = LabelGroup::Wall;				wallqueue << neighbor_label;			}		}	}	*/		grid.fill(NULL, grid_size.product());		for (uint gz = 0; gz < grid_size[2]; ++gz) {		for (uint gy = 0; gy < grid_size[1]; ++gy) {			for (uint gx = 0; gx < grid_size[0]; ++gx) {				const uint lx0 = grid_offset[0] + gx * (radius * 2 + 1) - radius;				const uint ly0 = grid_offset[1] + gy * (radius * 2 + 1) - radius;				const uint lz0 = grid_offset[2] + gz * (radius * 2 + 1) - radius;				const uint lx1 = lx0 + radius * 2;				const uint ly1 = ly0 + radius * 2;				const uint lz1 = lz0 + radius * 2;				uint count = 0;								for (uint lz = lz0; lz <= lz1; ++lz) {					for (uint ly = ly0; ly <= ly1; ++ly) {						for (uint lx = lx0; lx <= lx1; ++lx) {							if (labels[lz * labels_size[0] * labels_size[1] + ly * labels_size[0] + lx] == LabelGroup::Grown)								++count;						}					}				}								if (!count)					continue;								bool complete = count == (radius * 2 + 1) * (radius * 2 + 1) * (radius * 2 + 1);				Cell* cell = new Cell(UTriple(lx0 + radius, ly0 + radius, lz0 + radius),				                      UTriple(gx, gy, gz), complete);								cell->mActiveLabelCount = count;								grid[grid_size[0] * grid_size[1] * gz + grid_size[0] * gy + gx] = cell;								if (cell->mComplete) {					for (uint lz = lz0; lz <= lz1; ++lz) {						for (uint ly = ly0; ly <= ly1; ++ly) {							for (uint lx = lx0; lx <= lx1; ++lx) {								if (labels[lz * labels_size[0] * labels_size[1] + ly * labels_size[0] + lx] == LabelGroup::Grown) {									labels[lz * labels_size[0] * labels_size[1] + ly * labels_size[0] + lx] = LabelGroup::CompleteCell;																		if (cell->mActiveLabelCount > 0)										--cell->mActiveLabelCount;									else										qWarning("GrowingCoronarySegmentation execute: Tring to remove a label from an empty Cell (1)");								}							}						}					}										if (cell->mActiveLabelCount > 0)						qWarning("GrowingCoronarySegmentation execute: Removed Cell hast active labels");										cell->mRemoved = true;				}			}		}	}		// fill queue	uint rootindex = grid_root.linearized(grid_size);	Cell* rootcell = grid[rootindex];	Cell* neighbor_cell = NULL;	QQueue<Cell*> cellqueue;		qDebug("rootindex %u, cells %d", rootindex, grid.size());	qDebug("backup_label_root %s", qPrintable(backup_label_root.toString()));	qDebug("backup_labels_size %s", qPrintable(backup_labels_size.toString()));	qDebug("backup_grid_offset %s", qPrintable(backup_grid_offset.toString()));	qDebug("backup_grid_root %s", qPrintable(backup_grid_root.toString()));	qDebug("backup_grid_size %s", qPrintable(backup_grid_size.toString()));		if (!rootcell || !rootcell->mComplete) {		qWarning("GrowingCoronarySegmentation execute: Marker %s must be nearer to the center of the root vessel",		         qPrintable(label_root.toString()));		qDeleteAll(grid);		return;	}		cellqueue.enqueue(rootcell);		// update queue		while (!cellqueue.isEmpty()) {		Cell* cell = cellqueue.dequeue();				qDebug("cellqueue >>          cell, grid %s, label %s, active %u",		       qPrintable(cell->mCenter_grid.toString()),		       qPrintable(cell->mCenter_label.toString()),		       cell->mActiveLabelCount);				const uint lx0 = grid_offset[0] + cell->mCenter_grid[0] * (radius * 2 + 1) - radius;		const uint ly0 = grid_offset[1] + cell->mCenter_grid[1] * (radius * 2 + 1) - radius;		const uint lz0 = grid_offset[2] + cell->mCenter_grid[2] * (radius * 2 + 1) - radius;		const uint lx1 = lx0 + radius * 2;		const uint ly1 = ly0 + radius * 2;		const uint lz1 = lz0 + radius * 2;		Cell* neighbor_cells[26];		QQueue<UTriple> labelqueue;				for (int i = 0; i < 26; ++i) {			const int dx = neighborhood_complete[i][0];			const int dy = neighborhood_complete[i][1];			const int dz = neighborhood_complete[i][2];						if (dx < 0 && cell->mCenter_grid[0] <= 0)				continue;						if (dx > 0 && cell->mCenter_grid[0] >= grid_size[0] - 1)				continue;						if (dy < 0 && cell->mCenter_grid[1] <= 0)				continue;						if (dy > 0 && cell->mCenter_grid[1] >= grid_size[1] - 1)				continue;						if (dz < 0 && cell->mCenter_grid[2] <= 0)				continue;						if (dz > 0 && cell->mCenter_grid[2] >= grid_size[2] - 1)				continue;						neighbor_cells[i] = grid[cell->mCenter_grid.translated<int>(dx, dy, dz).linearized(grid_size)];		}				for (int i = 0; i < 26; ++i) {			const int dx = neighborhood_complete[i][0];			const int dy = neighborhood_complete[i][1];			const int dz = neighborhood_complete[i][2];			const int neighbor_type = neighborhood_complete[i][3];			Cell* neighbor_cell = neighbor_cells[i];						if (neighbor_cell && !neighbor_cell->mQueued) {				neighbor_cell->mQueued = true;				cellqueue.enqueue(neighbor_cell);								qDebug("cellqueue << neighbor_cell, grid %s, label %s, active %u",				       qPrintable(neighbor_cell->mCenter_grid.toString()),				       qPrintable(neighbor_cell->mCenter_label.toString()),				       neighbor_cell->mActiveLabelCount);			}						if (neighbor_cell && neighbor_cell->mComplete && !cell->mComplete && !cell->mRemoved) {				if (neighbor_type == NeighborType::Plane) {					if (dx < 0) {						for (uint lz = lz0; lz <= lz1; ++lz) {							for (uint ly = ly0; ly <= ly1; ++ly) {								const UTriple plane_label(lx0, ly, lz);																if (labels[plane_label.linearized(labels_size)] == LabelGroup::Grown) {									labels[plane_label.linearized(labels_size)] = LabelGroup::Plane;									labelqueue << plane_label;																		if (cell->mActiveLabelCount > 0)										--cell->mActiveLabelCount;									else										qWarning("GrowingCoronarySegmentation execute: Tring to remove a label "										         "from an empty Cell (2): grid %s, label %s",										         qPrintable(cell->mCenter_grid.toString()),										         qPrintable(cell->mCenter_label.toString()));								}							}						}					}					else if (dx > 0) {						for (uint lz = lz0; lz <= lz1; ++lz) {							for (uint ly = ly0; ly <= ly1; ++ly) {								const UTriple plane_label(lx1, ly, lz);																if (labels[plane_label.linearized(labels_size)] == LabelGroup::Grown) {									labels[plane_label.linearized(labels_size)] = LabelGroup::Plane;									labelqueue << plane_label;																		if (cell->mActiveLabelCount > 0)										--cell->mActiveLabelCount;									else										qWarning("GrowingCoronarySegmentation execute: Tring to remove a label "										         "from an empty Cell (3): grid %s, label %s",										         qPrintable(cell->mCenter_grid.toString()),										         qPrintable(cell->mCenter_label.toString()));								}							}						}					}										if (dy < 0) {						for (uint lz = lz0; lz <= lz1; ++lz) {							for (uint lx = lx0; lx <= lx1; ++lx) {								const UTriple plane_label(lx, ly0, lz);																if (labels[plane_label.linearized(labels_size)] == LabelGroup::Grown) {									labels[plane_label.linearized(labels_size)] = LabelGroup::Plane;									labelqueue << plane_label;																		if (cell->mActiveLabelCount > 0)										--cell->mActiveLabelCount;									else										qWarning("GrowingCoronarySegmentation execute: Tring to remove a label "										         "from an empty Cell (4): grid %s, label %s",										         qPrintable(cell->mCenter_grid.toString()),										         qPrintable(cell->mCenter_label.toString()));								}							}						}					}					else if (dy > 0) {						for (uint lz = lz0; lz <= lz1; ++lz) {							for (uint lx = lx0; lx <= lx1; ++lx) {								const UTriple plane_label(lx, ly1, lz);																if (labels[plane_label.linearized(labels_size)] == LabelGroup::Grown) {									labels[plane_label.linearized(labels_size)] = LabelGroup::Plane;									labelqueue << plane_label;																		if (cell->mActiveLabelCount > 0)										--cell->mActiveLabelCount;									else										qWarning("GrowingCoronarySegmentation execute: Tring to remove a label "										         "from an empty Cell (5): grid %s, label %s",										         qPrintable(cell->mCenter_grid.toString()),										         qPrintable(cell->mCenter_label.toString()));								}							}						}					}										if (dz < 0) {						for (uint ly = ly0; ly <= ly1; ++ly) {							for (uint lx = lx0; lx <= lx1; ++lx) {								const UTriple plane_label(lx, ly, lz0);																if (labels[plane_label.linearized(labels_size)] == LabelGroup::Grown) {									labels[plane_label.linearized(labels_size)] = LabelGroup::Plane;									labelqueue << plane_label;																		if (cell->mActiveLabelCount > 0)										--cell->mActiveLabelCount;									else										qWarning("GrowingCoronarySegmentation execute: Tring to remove a label "										         "from an empty Cell (6): grid %s, label %s",										         qPrintable(cell->mCenter_grid.toString()),										         qPrintable(cell->mCenter_label.toString()));								}							}						}					}					else if (dz > 0) {						for (uint ly = ly0; ly <= ly1; ++ly) {							for (uint lx = lx0; lx <= lx1; ++lx) {								const UTriple plane_label(lx, ly, lz1);																if (labels[plane_label.linearized(labels_size)] == LabelGroup::Grown) {									labels[plane_label.linearized(labels_size)] = LabelGroup::Plane;									labelqueue << plane_label;																		if (cell->mActiveLabelCount > 0)										--cell->mActiveLabelCount;									else										qWarning("GrowingCoronarySegmentation execute: Tring to remove a label "										         "from an empty Cell (7): grid %s, label %s",										         qPrintable(cell->mCenter_grid.toString()),										         qPrintable(cell->mCenter_label.toString()));								}							}						}					}				}				else if (neighbor_type == NeighborType::Edge) {					const int apA = neighborhood_complete[i][4];					const int apB = neighborhood_complete[i][5];										if (apA < 0 || apB < 0)						qWarning("GrowingCoronarySegmentation execute: Edge neighbor with invalid adjacent plane neighbors");					else {						const Cell* neighbor_planeA = neighbor_cells[apA];						const Cell* neighbor_planeB = neighbor_cells[apB];												if (neighbor_planeA && neighbor_planeB) {							if (!dx) {								if (dy < 0 && dz < 0) {									for (uint lx = lx0; lx <= lx1; ++lx) {										const UTriple planeY_label(lx, ly0 - 1, lz0);										const UTriple planeZ_label(lx, ly0, lz0 - 1);																				if (   labels[planeY_label.linearized(labels_size)] != LabelGroup::Unexplored										    && labels[planeZ_label.linearized(labels_size)] != LabelGroup::Unexplored) {											const UTriple edge_label(lx, ly0, lz0);																						if (labels[edge_label.linearized(labels_size)] == LabelGroup::Grown) {												labels[edge_label.linearized(labels_size)] = LabelGroup::Edge;												labelqueue << edge_label;																								if (cell->mActiveLabelCount > 0)													--cell->mActiveLabelCount;												else													qWarning("GrowingCoronarySegmentation execute: Tring to remove a label "															 "from an empty Cell (a1): grid %s, label %s",															 qPrintable(cell->mCenter_grid.toString()),															 qPrintable(cell->mCenter_label.toString()));											}										}									}								}								else if (dy > 0 && dz < 0) {									for (uint lx = lx0; lx <= lx1; ++lx) {										const UTriple planeY_label(lx, ly1 + 1, lz0);										const UTriple planeZ_label(lx, ly1, lz0 - 1);																				if (   labels[planeY_label.linearized(labels_size)] != LabelGroup::Unexplored										    && labels[planeZ_label.linearized(labels_size)] != LabelGroup::Unexplored) {											const UTriple edge_label(lx, ly1, lz0);																						if (labels[edge_label.linearized(labels_size)] == LabelGroup::Grown) {												labels[edge_label.linearized(labels_size)] = LabelGroup::Edge;												labelqueue << edge_label;																								if (cell->mActiveLabelCount > 0)													--cell->mActiveLabelCount;												else													qWarning("GrowingCoronarySegmentation execute: Tring to remove a label "															 "from an empty Cell (a2): grid %s, label %s",															 qPrintable(cell->mCenter_grid.toString()),															 qPrintable(cell->mCenter_label.toString()));											}										}									}								}								else if (dy < 0 && dz > 0) {									for (uint lx = lx0; lx <= lx1; ++lx) {										const UTriple planeY_label(lx, ly0 - 1, lz1);										const UTriple planeZ_label(lx, ly0, lz1 + 1);																				if (   labels[planeY_label.linearized(labels_size)] != LabelGroup::Unexplored										    && labels[planeZ_label.linearized(labels_size)] != LabelGroup::Unexplored) {											const UTriple edge_label(lx, ly0, lz1);																						if (labels[edge_label.linearized(labels_size)] == LabelGroup::Grown) {												labels[edge_label.linearized(labels_size)] = LabelGroup::Edge;												labelqueue << edge_label;																								if (cell->mActiveLabelCount > 0)													--cell->mActiveLabelCount;												else													qWarning("GrowingCoronarySegmentation execute: Tring to remove a label "															 "from an empty Cell (a3): grid %s, label %s",															 qPrintable(cell->mCenter_grid.toString()),															 qPrintable(cell->mCenter_label.toString()));											}										}									}								}								else if (dy > 0 && dz > 0) {									for (uint lx = lx0; lx <= lx1; ++lx) {										const UTriple planeY_label(lx, ly1 + 1, lz1);										const UTriple planeZ_label(lx, ly1, lz1 + 1);																				if (   labels[planeY_label.linearized(labels_size)] != LabelGroup::Unexplored										    && labels[planeZ_label.linearized(labels_size)] != LabelGroup::Unexplored) {											const UTriple edge_label(lx, ly1, lz1);																						if (labels[edge_label.linearized(labels_size)] == LabelGroup::Grown) {												labels[edge_label.linearized(labels_size)] = LabelGroup::Edge;												labelqueue << edge_label;																								if (cell->mActiveLabelCount > 0)													--cell->mActiveLabelCount;												else													qWarning("GrowingCoronarySegmentation execute: Tring to remove a label "															 "from an empty Cell (a4): grid %s, label %s",															 qPrintable(cell->mCenter_grid.toString()),															 qPrintable(cell->mCenter_label.toString()));											}										}									}								}							}														if (!dy) {								if (dx < 0 && dz < 0) {									for (uint ly = ly0; ly <= ly1; ++ly) {										const UTriple planeX_label(lx0 - 1, ly, lz0);										const UTriple planeZ_label(lx0, ly, lz0 - 1);																				if (   labels[planeX_label.linearized(labels_size)] != LabelGroup::Unexplored										    && labels[planeZ_label.linearized(labels_size)] != LabelGroup::Unexplored) {											const UTriple edge_label(lx0, ly, lz0);																						if (labels[edge_label.linearized(labels_size)] == LabelGroup::Grown) {												labels[edge_label.linearized(labels_size)] = LabelGroup::Edge;												labelqueue << edge_label;																								if (cell->mActiveLabelCount > 0)													--cell->mActiveLabelCount;												else													qWarning("GrowingCoronarySegmentation execute: Tring to remove a label "															 "from an empty Cell (a1): grid %s, label %s",															 qPrintable(cell->mCenter_grid.toString()),															 qPrintable(cell->mCenter_label.toString()));											}										}									}								}								else if (dx > 0 && dz < 0) {									for (uint ly = ly0; ly <= ly1; ++ly) {										const UTriple planeX_label(lx1 + 1, ly, lz0);										const UTriple planeZ_label(lx1, ly, lz0 - 1);																				if (   labels[planeX_label.linearized(labels_size)] != LabelGroup::Unexplored										    && labels[planeZ_label.linearized(labels_size)] != LabelGroup::Unexplored) {											const UTriple edge_label(lx1, ly, lz0);																						if (labels[edge_label.linearized(labels_size)] == LabelGroup::Grown) {												labels[edge_label.linearized(labels_size)] = LabelGroup::Edge;												labelqueue << edge_label;																								if (cell->mActiveLabelCount > 0)													--cell->mActiveLabelCount;												else													qWarning("GrowingCoronarySegmentation execute: Tring to remove a label "															 "from an empty Cell (a2): grid %s, label %s",															 qPrintable(cell->mCenter_grid.toString()),															 qPrintable(cell->mCenter_label.toString()));											}										}									}								}								else if (dx < 0 && dz > 0) {									for (uint ly = ly0; ly <= ly1; ++ly) {										const UTriple planeX_label(lx0 - 1, ly, lz1);										const UTriple planeZ_label(lx0, ly, lz1 + 1);																				if (   labels[planeX_label.linearized(labels_size)] != LabelGroup::Unexplored										    && labels[planeZ_label.linearized(labels_size)] != LabelGroup::Unexplored) {											const UTriple edge_label(lx0, ly, lz1);																						if (labels[edge_label.linearized(labels_size)] == LabelGroup::Grown) {												labels[edge_label.linearized(labels_size)] = LabelGroup::Edge;												labelqueue << edge_label;																								if (cell->mActiveLabelCount > 0)													--cell->mActiveLabelCount;												else													qWarning("GrowingCoronarySegmentation execute: Tring to remove a label "															 "from an empty Cell (a3): grid %s, label %s",															 qPrintable(cell->mCenter_grid.toString()),															 qPrintable(cell->mCenter_label.toString()));											}										}									}								}								else if (dx > 0 && dz > 0) {									for (uint ly = ly0; ly <= ly1; ++ly) {										const UTriple planeX_label(lx1 + 1, ly, lz1);										const UTriple planeZ_label(lx1, ly, lz1 + 1);																				if (   labels[planeX_label.linearized(labels_size)] != LabelGroup::Unexplored										    && labels[planeZ_label.linearized(labels_size)] != LabelGroup::Unexplored) {											const UTriple edge_label(lx1, ly, lz1);																						if (labels[edge_label.linearized(labels_size)] == LabelGroup::Grown) {												labels[edge_label.linearized(labels_size)] = LabelGroup::Edge;												labelqueue << edge_label;																								if (cell->mActiveLabelCount > 0)													--cell->mActiveLabelCount;												else													qWarning("GrowingCoronarySegmentation execute: Tring to remove a label "															 "from an empty Cell (a4): grid %s, label %s",															 qPrintable(cell->mCenter_grid.toString()),															 qPrintable(cell->mCenter_label.toString()));											}										}									}								}							}														if (!dz) {								if (dx < 0 && dy < 0) {									for (uint lz = lz0; lz <= lz1; ++lz) {										const UTriple planeX_label(lx0 - 1, ly0, lz);										const UTriple planeY_label(lx0, ly0 - 1, lz);																				if (   labels[planeX_label.linearized(labels_size)] != LabelGroup::Unexplored										    && labels[planeY_label.linearized(labels_size)] != LabelGroup::Unexplored) {											const UTriple edge_label(lx0, ly0, lz);																						if (labels[edge_label.linearized(labels_size)] == LabelGroup::Grown) {												labels[edge_label.linearized(labels_size)] = LabelGroup::Edge;												labelqueue << edge_label;																								if (cell->mActiveLabelCount > 0)													--cell->mActiveLabelCount;												else													qWarning("GrowingCoronarySegmentation execute: Tring to remove a label "															 "from an empty Cell (a1): grid %s, label %s",															 qPrintable(cell->mCenter_grid.toString()),															 qPrintable(cell->mCenter_label.toString()));											}										}									}								}								else if (dx > 0 && dy < 0) {									for (uint lz = lz0; lz <= lz1; ++lz) {										const UTriple planeX_label(lx1 + 1, ly0, lz);										const UTriple planeY_label(lx1, ly0 - 1, lz);																				if (   labels[planeY_label.linearized(labels_size)] != LabelGroup::Unexplored										    && labels[planeY_label.linearized(labels_size)] != LabelGroup::Unexplored) {											const UTriple edge_label(lx1, ly0, lz);																						if (labels[edge_label.linearized(labels_size)] == LabelGroup::Grown) {												labels[edge_label.linearized(labels_size)] = LabelGroup::Edge;												labelqueue << edge_label;																								if (cell->mActiveLabelCount > 0)													--cell->mActiveLabelCount;												else													qWarning("GrowingCoronarySegmentation execute: Tring to remove a label "															 "from an empty Cell (a2): grid %s, label %s",															 qPrintable(cell->mCenter_grid.toString()),															 qPrintable(cell->mCenter_label.toString()));											}										}									}								}								else if (dx < 0 && dy > 0) {									for (uint lz = lz0; lz <= lz1; ++lz) {										const UTriple planeX_label(lx0 - 1, ly1, lz);										const UTriple planeY_label(lx0, ly1 + 1, lz);																				if (   labels[planeX_label.linearized(labels_size)] != LabelGroup::Unexplored										    && labels[planeY_label.linearized(labels_size)] != LabelGroup::Unexplored) {											const UTriple edge_label(lx0, ly1, lz);																						if (labels[edge_label.linearized(labels_size)] == LabelGroup::Grown) {												labels[edge_label.linearized(labels_size)] = LabelGroup::Edge;												labelqueue << edge_label;																								if (cell->mActiveLabelCount > 0)													--cell->mActiveLabelCount;												else													qWarning("GrowingCoronarySegmentation execute: Tring to remove a label "															 "from an empty Cell (a3): grid %s, label %s",															 qPrintable(cell->mCenter_grid.toString()),															 qPrintable(cell->mCenter_label.toString()));											}										}									}								}								else if (dx > 0 && dy > 0) {									for (uint lz = lz0; lz <= lz1; ++lz) {										const UTriple planeX_label(lx1 + 1, ly1, lz);										const UTriple planeY_label(lx1, ly1 + 1, lz);																				if (   labels[planeX_label.linearized(labels_size)] != LabelGroup::Unexplored										    && labels[planeY_label.linearized(labels_size)] != LabelGroup::Unexplored) {											const UTriple edge_label(lx1, ly1, lz);																						if (labels[edge_label.linearized(labels_size)] == LabelGroup::Grown) {												labels[edge_label.linearized(labels_size)] = LabelGroup::Edge;												labelqueue << edge_label;																								if (cell->mActiveLabelCount > 0)													--cell->mActiveLabelCount;												else													qWarning("GrowingCoronarySegmentation execute: Tring to remove a label "															 "from an empty Cell (a4): grid %s, label %s",															 qPrintable(cell->mCenter_grid.toString()),															 qPrintable(cell->mCenter_label.toString()));											}										}									}								}							}						}					}				}			}		}				while (!labelqueue.isEmpty()) {			const UTriple label = labelqueue.dequeue();						for (int k = 0; k < 6; ++k) {				const int ldx = neighborhood_direct[k][0];				const int ldy = neighborhood_direct[k][1];				const int ldz = neighborhood_direct[k][2];								if (ldx < 0 && label[0] <= lx0)					continue;								if (ldx > 0 && label[0] >= lx1)					continue;								if (ldy < 0 && label[1] <= ly0)					continue;								if (ldy > 0 && label[1] >= ly1)					continue;								if (ldz < 0 && label[2] <= lz0)					continue;								if (ldz > 0 && label[2] >= lz1)					continue;								const UTriple neighbor_label = label.translated<int>(ldx, ldy, ldz);								if (labels[neighbor_label.linearized(labels_size)] == LabelGroup::Grown) {					labels[neighbor_label.linearized(labels_size)] = LabelGroup::IncompleteCell;					labelqueue << neighbor_label;										if (cell->mActiveLabelCount > 0)						--cell->mActiveLabelCount;					else						qWarning("GrowingCoronarySegmentation execute: Tring to remove a label %s "						         "from an empty Cell (8): grid %s, label %s",						         qPrintable(neighbor_label.toString()),						         qPrintable(cell->mCenter_grid.toString()),						         qPrintable(cell->mCenter_label.toString()));				}			}		}				if (!cell->mActiveLabelCount) {			cell->mRemoved = true;			qDebug("remove cell, grid %s, label %s",				   qPrintable(cell->mCenter_grid.toString()),				   qPrintable(cell->mCenter_label.toString()));		}	}		// shell	for (uint gz = 0; gz < grid_size[2]; ++gz) {		for (uint gy = 0; gy < grid_size[1]; ++gy) {			for (uint gx = 0; gx < grid_size[0]; ++gx) {				const uint lx0 = grid_offset[0] + gx * (radius * 2 + 1) - radius;				const uint ly0 = grid_offset[1] + gy * (radius * 2 + 1) - radius;				const uint lz0 = grid_offset[2] + gz * (radius * 2 + 1) - radius;				const uint lx1 = lx0 + radius * 2;				const uint ly1 = ly0 + radius * 2;				const uint lz1 = lz0 + radius * 2;				Cell* cell = grid[grid_size[0] * grid_size[1] * gz + grid_size[0] * gy + gx];								if (!cell)					continue;								for (uint lz = lz0; lz <= lz1; ++lz) {					for (uint ly = ly0; ly <= ly1; ++ly) {						for (uint lx = lx0; lx <= lx1; ++lx) {							if (labels[lz * labels_size[0] * labels_size[1] + ly * labels_size[0] + lx] == LabelGroup::Unexplored)								labels[lz * labels_size[0] * labels_size[1] + ly * labels_size[0] + lx] = LabelGroup::Shell;						}					}				}			}		}	}		qDeleteAll(grid);