public void Sort(VectorPOD_RangeAdaptor dataToSort, uint beg, uint end) { if (end == beg) { return; } else { uint pivot = GetPivotPoint(dataToSort, beg, end); if (pivot > beg) { Sort(dataToSort, beg, pivot - 1); } if (pivot < end) { Sort(dataToSort, pivot + 1, end); } } }
private uint GetPivotPoint(VectorPOD_RangeAdaptor dataToSort, uint begPoint, uint endPoint) { uint pivot = begPoint; uint m = begPoint + 1; uint n = endPoint; while ((m < endPoint) && dataToSort[pivot] >= dataToSort[m]) { m++; } while ((n > begPoint) && (dataToSort[pivot] <= dataToSort[n])) { n--; } while (m < n) { uint temp = dataToSort[m]; dataToSort[m] = dataToSort[n]; dataToSort[n] = temp; while ((m < endPoint) && (dataToSort[pivot] >= dataToSort[m])) { m++; } while ((n > begPoint) && (dataToSort[pivot] <= dataToSort[n])) { n--; } } if (pivot != n) { uint temp2 = dataToSort[n]; dataToSort[n] = dataToSort[pivot]; dataToSort[pivot] = temp2; } return(n); }
// Returns the number of styles public int sweep_styles() { for(;;) { if(m_scan_y > m_Rasterizer.max_y()) return 0; int num_cells = (int)m_Rasterizer.scanline_num_cells(m_scan_y); cell_aa[] cells; int cellOffset = 0; int curCellOffset; m_Rasterizer.scanline_cells(m_scan_y, out cells, out cellOffset); int num_styles = (int)(m_max_style - m_min_style + 2); int style_id; int styleOffset = 0; m_cells.Allocate((int)num_cells * 2, 256); // Each cell can have two styles m_ast.Capacity(num_styles, 64); m_asm.Allocate((num_styles + 7) >> 3, 8); m_asm.zero(); if(num_cells > 0) { // Pre-add zero (for no-fill style, that is, -1). // We need that to ensure that the "-1 style" would go first. m_asm.Array[0] |= 1; m_ast.add(0); m_styles.Array[styleOffset].start_cell = 0; m_styles.Array[styleOffset].num_cells = 0; m_styles.Array[styleOffset].last_x = -0x7FFFFFFF; m_sl_start = cells[0].x; m_sl_len = (int)(cells[num_cells-1].x - m_sl_start + 1); while(num_cells-- != 0) { curCellOffset = (int)cellOffset++; add_style(cells[curCellOffset].left); add_style(cells[curCellOffset].right); } // Convert the Y-histogram into the array of starting indexes int i; int start_cell = 0; style_info[] stylesArray = m_styles.Array; for(i = 0; i < m_ast.size(); i++) { int IndexToModify = (int)m_ast[i]; int v = stylesArray[IndexToModify].start_cell; stylesArray[IndexToModify].start_cell = start_cell; start_cell += v; } num_cells = (int)m_Rasterizer.scanline_num_cells(m_scan_y); m_Rasterizer.scanline_cells(m_scan_y, out cells, out cellOffset); while(num_cells-- > 0) { curCellOffset = (int)cellOffset++; style_id = (int)((cells[curCellOffset].left < 0) ? 0 : cells[curCellOffset].left - m_min_style + 1); styleOffset = (int)style_id; if (cells[curCellOffset].x == stylesArray[styleOffset].last_x) { cellOffset = stylesArray[styleOffset].start_cell + stylesArray[styleOffset].num_cells - 1; unchecked { cells[cellOffset].area += cells[curCellOffset].area; cells[cellOffset].cover += cells[curCellOffset].cover; } } else { cellOffset = stylesArray[styleOffset].start_cell + stylesArray[styleOffset].num_cells; cells[cellOffset].x = cells[curCellOffset].x; cells[cellOffset].area = cells[curCellOffset].area; cells[cellOffset].cover = cells[curCellOffset].cover; stylesArray[styleOffset].last_x = cells[curCellOffset].x; stylesArray[styleOffset].num_cells++; } style_id = (int)((cells[curCellOffset].right < 0) ? 0 : cells[curCellOffset].right - m_min_style + 1); styleOffset = (int)style_id; if (cells[curCellOffset].x == stylesArray[styleOffset].last_x) { cellOffset = stylesArray[styleOffset].start_cell + stylesArray[styleOffset].num_cells - 1; unchecked { cells[cellOffset].area -= cells[curCellOffset].area; cells[cellOffset].cover -= cells[curCellOffset].cover; } } else { cellOffset = stylesArray[styleOffset].start_cell + stylesArray[styleOffset].num_cells; cells[cellOffset].x = cells[curCellOffset].x; cells[cellOffset].area = -cells[curCellOffset].area; cells[cellOffset].cover = -cells[curCellOffset].cover; stylesArray[styleOffset].last_x = cells[curCellOffset].x; stylesArray[styleOffset].num_cells++; } } } if(m_ast.size() > 1) break; ++m_scan_y; } ++m_scan_y; if (m_layer_order != layer_order_e.layer_unsorted) { VectorPOD_RangeAdaptor ra = new VectorPOD_RangeAdaptor(m_ast, 1, m_ast.size() - 1); if (m_layer_order == layer_order_e.layer_direct) { QuickSort_range_adaptor_uint m_QSorter = new QuickSort_range_adaptor_uint(); m_QSorter.Sort(ra); //quick_sort(ra, uint_greater); } else { throw new System.NotImplementedException(); //QuickSort_range_adaptor_uint m_QSorter = new QuickSort_range_adaptor_uint(); //m_QSorter.Sort(ra); //quick_sort(ra, uint_less); } } return m_ast.size() - 1; }
///<summary> ///</summary> ///<returns></returns> ///<exception cref="NotImplementedException"></exception> public uint SweepStyles() { for (; ; ) { if (_scanY > _rasterizer.MaxY()) return 0; int numCells = (int)_rasterizer.ScanlineNumCells((uint)_scanY); AntiAliasingCell[] cells; uint cellOffset; _rasterizer.ScanlineCells((uint)_scanY, out cells, out cellOffset); uint numStyles = (uint)(_maxStyle - _minStyle + 2); int styleOffset = 0; _cells.Allocate((uint)numCells * 2, 256); // Each cell can have two Styles _activeStyleTable.Capacity(numStyles, 64); _activeStyleMask.Allocate((numStyles + 7) >> 3, 8); _activeStyleMask.Zero(); if (numCells > 0) { // Pre-Add zero (for no-fill Style, that is, -1). // We need that to ensure that the "-1 Style" would go first. _activeStyleMask.Array[0] |= 1; _activeStyleTable.Add(0); _activeStyles.Array[styleOffset].StartCell = 0; _activeStyles.Array[styleOffset].NumCells = 0; _activeStyles.Array[styleOffset].LastX = -0x7FFFFFFF; _scanlineStart = cells[0].x; _scanlineLength = (uint)(cells[numCells - 1].x - _scanlineStart + 1); int curCellOffset; while (numCells-- != 0) { curCellOffset = (int)cellOffset++; AddStyle(cells[curCellOffset].left); AddStyle(cells[curCellOffset].right); } // Convert the Y-histogram into the array of starting indexes uint i = 0u; uint startCell = 0; StyleInfo[] stylesArray = _activeStyles.Array; int indexToModify = (int)_activeStyleTable[i]; for (i = 0; i < _activeStyleTable.Size(); i++) { uint v = stylesArray[indexToModify].StartCell; stylesArray[indexToModify].StartCell = startCell; startCell += v; } numCells = (int)_rasterizer.ScanlineNumCells((uint)_scanY); _rasterizer.ScanlineCells((uint)_scanY, out cells, out cellOffset); while (numCells-- > 0) { curCellOffset = (int)cellOffset; uint styleId = (uint)((cells[curCellOffset].left < 0) ? 0 : cells[curCellOffset].left - _minStyle + 1); styleOffset = (int)styleId; if (cells[curCellOffset].x == stylesArray[styleOffset].LastX) { cellOffset = stylesArray[styleOffset].StartCell + stylesArray[styleOffset].NumCells - 1; unchecked { cells[cellOffset].area += cells[curCellOffset].area; cells[cellOffset].cover += cells[curCellOffset].cover; } } else { cellOffset = stylesArray[styleOffset].StartCell + stylesArray[styleOffset].NumCells; cells[cellOffset].x = cells[curCellOffset].x; cells[cellOffset].area = cells[curCellOffset].area; cells[cellOffset].cover = cells[curCellOffset].cover; stylesArray[styleOffset].LastX = cells[curCellOffset].x; stylesArray[styleOffset].NumCells++; } styleId = (uint)((cells[curCellOffset].right < 0) ? 0 : cells[curCellOffset].right - _minStyle + 1); styleOffset = (int)styleId; if (cells[curCellOffset].x == stylesArray[styleOffset].LastX) { cellOffset = stylesArray[styleOffset].StartCell + stylesArray[styleOffset].NumCells - 1; unchecked { cells[cellOffset].area -= cells[curCellOffset].area; cells[cellOffset].cover -= cells[curCellOffset].cover; } } else { cellOffset = stylesArray[styleOffset].StartCell + stylesArray[styleOffset].NumCells; cells[cellOffset].x = cells[curCellOffset].x; cells[cellOffset].area = -cells[curCellOffset].area; cells[cellOffset].cover = -cells[curCellOffset].cover; stylesArray[styleOffset].LastX = cells[curCellOffset].x; stylesArray[styleOffset].NumCells++; } } } if (_activeStyleTable.Size() > 1) break; ++_scanY; } ++_scanY; if (_layerOrder != ELayerOrder.LayerUnsorted) { VectorPOD_RangeAdaptor ra = new VectorPOD_RangeAdaptor(_activeStyleTable, 1, _activeStyleTable.Size() - 1); if (_layerOrder == ELayerOrder.LayerDirect) { QuickSortRangeAdaptorUint mQSorter = new QuickSortRangeAdaptorUint(); mQSorter.Sort(ra); //quick_sort(ra, uint_greater); } else { throw new NotImplementedException(); //QuickSortRangeAdaptorUint m_QSorter = new QuickSortRangeAdaptorUint(); //m_QSorter.Sort(ra); //quick_sort(ra, uint_less); } } return _activeStyleTable.Size() - 1; }
private uint GetPivotPoint(VectorPOD_RangeAdaptor dataToSort, uint begPoint, uint endPoint) { uint pivot = begPoint; uint m = begPoint + 1; uint n = endPoint; while ((m < endPoint) && dataToSort[pivot] >= dataToSort[m]) { m++; } while ((n > begPoint) && (dataToSort[pivot] <= dataToSort[n])) { n--; } while (m < n) { uint temp = dataToSort[m]; dataToSort[m] = dataToSort[n]; dataToSort[n] = temp; while ((m < endPoint) && (dataToSort[pivot] >= dataToSort[m])) { m++; } while ((n > begPoint) && (dataToSort[pivot] <= dataToSort[n])) { n--; } } if (pivot != n) { uint temp2 = dataToSort[n]; dataToSort[n] = dataToSort[pivot]; dataToSort[pivot] = temp2; } return n; }
public void Sort(VectorPOD_RangeAdaptor dataToSort) { Sort(dataToSort, 0, (uint)(dataToSort.Size() - 1)); }