예제 #1
0
bool GameAlgorithm::hasStillAChance( void )
{
	for (int row = 0; row < m_nSideLen; row++)
	{
		for (int col = 0; col < m_nSideLen-1; col++)
		{
			if (mergePoints(m_board[row][col], m_board[row][col+1]) != ZERO)
			{
				return true;
			}
		}
	}

	for (int col = 0; col < m_nSideLen; col++)
	{
		for (int row = 0; row < m_nSideLen-1; row++)
		{
			if (mergePoints(m_board[row][col], m_board[row+1][col]) != ZERO)
			{
				return true;
			}
		}
	}

	return false;
}
예제 #2
0
// Calculate geometrically collocated points, Requires PackedList to be
// sized and initalised!
Foam::label Foam::autoSnapDriver::getCollocatedPoints
(
    const scalar tol,
    const pointField& points,
    PackedBoolList& isCollocatedPoint
)
{
    labelList pointMap;
    label nUnique = mergePoints
    (
        points,                         // points
        tol,                            // mergeTol
        false,                          // verbose
        pointMap
    );
    bool hasMerged = (nUnique < points.size());

    if (!returnReduce(hasMerged, orOp<bool>()))
    {
        return 0;
    }

    // Determine which merged points are referenced more than once
    label nCollocated = 0;

    // Per old point the newPoint. Or -1 (not set yet) or -2 (already seen
    // twice)
    labelList firstOldPoint(nUnique, -1);
    forAll(pointMap, oldPointI)
    {
        label newPointI = pointMap[oldPointI];

        if (firstOldPoint[newPointI] == -1)
        {
            // First use of oldPointI. Store.
            firstOldPoint[newPointI] = oldPointI;
        }
        else if (firstOldPoint[newPointI] == -2)
        {
            // Third or more reference of oldPointI -> non-manifold
            isCollocatedPoint.set(oldPointI, 1u);
            nCollocated++;
        }
        else
        {
            // Second reference of oldPointI -> non-manifold
            isCollocatedPoint.set(firstOldPoint[newPointI], 1u);
            nCollocated++;

            isCollocatedPoint.set(oldPointI, 1u);
            nCollocated++;

            // Mark with special value to save checking next time round
            firstOldPoint[newPointI] = -2;
        }
    }
예제 #3
0
void GameAlgorithm::mergeRight()
{
	for (int row = 0; row < m_nSideLen; row++)
	{
		for (int col = m_nSideLen-2; col >= 0; col--)
		{
			int val = mergePoints(m_board[row][col], m_board[row][col+1]);
			if (val != ZERO)
			{
				m_board[row][col+1] = val;
                m_board[row][col+1].m = true;
				m_board[row][col+1].ids.push_back(m_board[row][col].ids.back());
				m_board[row][col] = ZERO;
				m_nScore+= val;
			}
		}
	}
}
예제 #4
0
void GameAlgorithm::mergeDown()
{
	for (int row = m_nSideLen-2; row >= 0; row--)
	{
		for (int col = 0; col < m_nSideLen; col++)
		{
			int val = mergePoints(m_board[row][col], m_board[row+1][col]);
			if (val != ZERO)
			{
				m_board[row+1][col] = val;
                m_board[row+1][col].m = true;
				m_board[row+1][col].ids.push_back(m_board[row][col].ids.back());
				m_board[row][col] = ZERO;
				m_nScore+= val;
			}
		}
	}
}
예제 #5
0
int GEOObjects::mergeGeometries (std::vector<std::string> const & geo_names,
                                  std::string &merged_geo_name)
{
	const std::size_t n_geo_names(geo_names.size());

	if (n_geo_names < 2)
		return 0;

	std::vector<std::size_t> pnt_offsets(n_geo_names, 0);

	if (! mergePoints(geo_names, merged_geo_name, pnt_offsets))
		return -1;

	mergePolylines(geo_names, merged_geo_name, pnt_offsets);

	mergeSurfaces(geo_names, merged_geo_name, pnt_offsets);

	return 1;
}
예제 #6
0
WaveFile * markOutFileByF0A0(SimpleGraphData *data)
{
    SPTK_SETTINGS * sptk_settings = SettingsDialog::getSPTKsettings();

    WaveFile * waveFile = data->file_data;
    qDebug() << "waveOpenHFile" << LOG_DATA;

    int size = littleEndianBytesToUInt32(waveFile->dataChunk->chunkDataSize);
    qDebug() << "file size " << size << LOG_DATA;

    int pitchLogSize = data->d_pitch_log.x;
    qDebug() << "pitch size " << pitchLogSize << LOG_DATA;

    int intensiveSize = data->d_intensive_norm.x;
    qDebug() << "intensive size " << intensiveSize << LOG_DATA;

    double intensiveScaleFactor = 1.0 * size / CHAR_BIT_RECORD / intensiveSize;
    qDebug() << "intensiveScaleFactor " << intensiveScaleFactor << LOG_DATA;

    double pitchLogScaleFactor = 1.0 * size / CHAR_BIT_RECORD / pitchLogSize;
    qDebug() << "pitchLogScaleFactor " << pitchLogScaleFactor << LOG_DATA;

    double intensiveLimit = 1.0 * sptk_settings->dp->markoutA0limit / 100;
    qDebug() << "intensive_limit " << intensiveLimit << LOG_DATA;

    Points intensivePoints = getPoints(
                intensiveSize,
                data->d_intensive_norm,
                intensiveScaleFactor,
                intensiveLimit,
                sptk_settings->dp->relative_limit
    );
    Points pitchLogPoints = getPoints(
                pitchLogSize,
                data->d_pitch_log,
                pitchLogScaleFactor,
                MASK_LIMIT
    );

    int waveDataSize = littleEndianBytesToUInt32(waveFile->dataChunk->chunkDataSize);
    char* waveData = (char*) malloc(waveDataSize);
    memcpy(waveData, waveFile->dataChunk->waveformData, waveDataSize);

    qDebug() << "waveData " << waveData << LOG_DATA;
    qDebug() << "waveDataSize " << waveDataSize << LOG_DATA;
    qDebug() << "NUMBER_OF_CHANNELS " << NUMBER_OF_CHANNELS << LOG_DATA;
    qDebug() << "RECORD_FREQ " << RECORD_FREQ << LOG_DATA;
    qDebug() << "SIGNIFICANT_BITS_PER_SAMPLE " << SIGNIFICANT_BITS_PER_SAMPLE << LOG_DATA;

    qDebug() << "intensivePointsCount " << intensivePoints.pointsCount << LOG_DATA;
    qDebug() << "intensivePointsOffset " << intensivePoints.pointsOffset << LOG_DATA;
    qDebug() << "intensivePointsLenght " << intensivePoints.pointsLenght << LOG_DATA;
    qDebug() << "intensivePointsLabel " << intensivePoints.pointsLabels << LOG_DATA;

    qDebug() << "pitchLogPointsCount " << pitchLogPoints.pointsCount << LOG_DATA;
    qDebug() << "pitchLogPointsOffset " << pitchLogPoints.pointsOffset << LOG_DATA;
    qDebug() << "pitchLogPointsLenght " << pitchLogPoints.pointsLenght << LOG_DATA;
    qDebug() << "pitchLogPointsLabel " << pitchLogPoints.pointsLabels << LOG_DATA;

    Points points = mergePoints(intensivePoints, pitchLogPoints);

    qDebug() << "pointsCount " << points.pointsCount << LOG_DATA;
    qDebug() << "pointsOffset " << points.pointsOffset << LOG_DATA;
    qDebug() << "pointsLenght " << points.pointsLenght << LOG_DATA;
    qDebug() << "pointsLabel " << points.pointsLabels << LOG_DATA;

    return makeWaveFileFromRawData(
                waveData,
                waveDataSize,
                NUMBER_OF_CHANNELS,
                RECORD_FREQ,
                SIGNIFICANT_BITS_PER_SAMPLE,
                points.pointsCount,
                points.pointsOffset,
                points.pointsLenght,
                points.pointsLabels
    );
}
예제 #7
0
void PointTree::queryPoints(const Rect& rect, int count, std::vector<Point>& r) {
	r.clear();

	// only when r has 'count' elements
	// that way we can skip nodes with min_rank > worst_rank
	int32_t worst_rank = std::numeric_limits<int32_t>::max();

	for (Node* node : root) {
		if (Rect::Inside(node->bounds, rect)) {
			auto bn = static_cast<BranchNode*>(node);

			worst_rank = mergePoints(r, count, worst_rank, bn->best_pts, bn->num_best_points, nullptr);
		} else if (Rect::Intersects(node->bounds, rect)) {
			q.push_back(node);
		}
	}

	while (!q.empty()) {
		Node* node = q.back();
		q.pop_back();

		if (node->level > 0) {
			auto bn = static_cast<BranchNode*>(node);
			//printf("BranchLeaf (%.3f %.3f) (%.3f %.3f) - %d %d %d - %d\n", bn->bounds.lx, bn->bounds.ly, bn->bounds.hx, bn->bounds.hy, q.size(), bn->level, bn->count, worst_rank);
			//printf("Intersect with (%f %f) (%f %f)\n", rect.lx, rect.ly, rect.hx, rect.hy);

			int q_end = q.size();

			for (int i = 0; i < bn->count; i++) {
				// Children are ordered by rank
				if (bn->children_data[i].rank > worst_rank) {
					break;
				}

				if (!Rect::Intersects(bn->children_data[i].bounds, rect)) {
					continue;
				}

				auto child = bn->children[i];
				bool competely_inside = Rect::Inside(bn->children_data[i].bounds, rect);

				if (bn->children_data[i].level == 0) {
					auto leaf = static_cast<LeafNode*>(child);

					//_mm_prefetch((const char *) leaf->pts, _MM_HINT_T0);

					worst_rank = mergePoints(r, count, worst_rank, leaf->pts, leaf->count, competely_inside ? nullptr : &rect);
				}
				else if (competely_inside) {
					auto bn = static_cast<BranchNode*>(child);

					worst_rank = mergePoints(r, count, worst_rank, bn->best_pts, bn->num_best_points, nullptr);
				} else {
					q.push_back(child);
				}
			}

			// Few ms fater since children as pushed on backwards (largest rank to lowest)
			std::reverse(q.begin() + q_end, q.end());
		}
	}
}