/*
 * Add an Edge computed externally.  The label on the Edge is assumed
 * to be correct.
 */
void
GeometryGraph::addEdge(Edge *e)
{
	insertEdge(e);
	const CoordinateSequence* coord=e->getCoordinates();
	// insert the endpoint as a node, to mark that it is on the boundary
	insertPoint(argIndex,coord->getAt(0),Location::BOUNDARY);
	insertPoint(argIndex,coord->getAt(coord->getSize()-1),Location::BOUNDARY);
}
Exemplo n.º 2
0
void Foam::CV2D::insertBoundingBox()
{
    Info<< "insertBoundingBox: creating bounding mesh" << endl;
    scalar bigSpan = 10*meshControls().span();
    insertPoint(point2D(-bigSpan, -bigSpan), Vb::FAR_POINT);
    insertPoint(point2D(-bigSpan, bigSpan), Vb::FAR_POINT);
    insertPoint(point2D(bigSpan, -bigSpan), Vb::FAR_POINT);
    insertPoint(point2D(bigSpan, bigSpan), Vb::FAR_POINT);
}
void KarbonCalligraphicShape::appendPointsToPathAux(const QPointF &p1,
        const QPointF &p2)
{
    KoPathPoint *pathPoint1 = new KoPathPoint(this, p1);
    KoPathPoint *pathPoint2 = new KoPathPoint(this, p2);

    // calculate the index of the insertion position
    int index = pointCount() / 2;

    insertPoint(pathPoint2, KoPathPointIndex(0, index));
    insertPoint(pathPoint1, KoPathPointIndex(0, index));
}
Exemplo n.º 4
0
void CQuadTree::insertPoint(int x, int y, int hashvalue, CNode * root)
{
	// hash set
	//if (root->m_hashSet.find(hashvalue) == root->m_hashSet.end())
	//	root->m_hashSet.insert(hashvalue);

	if (root->m_children[0] != NULL)
	{
		int idx = root->getIndex(x, y);
		insertPoint(x, y, hashvalue, root->m_children[idx]);
	}
	else
	{
		map<unsigned int, Template*> &data = root->m_data;
		if (data.find(hashvalue) == data.end())
		{
			data[hashvalue] = new Template(x,y);
		}
		else
		{
			Template* tmp = new Template(x, y);
			tmp->next = data[hashvalue];
			data[hashvalue] = tmp;
		}


		root->m_count++;

		// split
		if (root->m_count > m_nodeCapacity && root->m_depth < m_maxDepth)
		{
			root->split();
		}
	}
}
Exemplo n.º 5
0
void ofxPolygonMask::mousePressed(ofMouseEventArgs &m) {
	if(doPoint) {
		focusedPoint = insertPoint(ofVec3f(m.x, m.y, 20));
		selectedPoint = focusedPoint;
		return;
	} else if(doDelete) {
		for(int i = 0; i < points.size(); i++) {
			if(sqrDist(m.x, m.y, points[i].x, points[i].y)<SQR_DIST_POINT_GRAB) { // 5 pixels distance
				points.erase(points.begin()+i);
				return;
			}
		}
		
	}
	
	for(int i = 0; i < points.size(); i++) {
		if(sqrDist(m.x, m.y, points[i].x, points[i].y)<SQR_DIST_POINT_GRAB) { // 5 pixels distance
			selectedPoint = i;
			focusedPoint = i;
			//points[selectedPoint].x = m.x;
			//points[selectedPoint].y = m.y;

		}
	}
}
void KarbonCalligraphicShape::addCap(int index1, int index2, int pointIndex,
                                     bool inverted)
{
    QPointF p1 = m_points[index1]->point();
    QPointF p2 = m_points[index2]->point();

    // TODO: review why spikes can appear with a lower limit
    QPointF delta = p2 - p1;
    if (delta.manhattanLength() < 1.0)
        return;

    QPointF direction = QLineF(QPointF(0, 0), delta).unitVector().p2();
    qreal width = m_points[index2]->width();
    QPointF p = p2 + direction * m_caps * width;

    KoPathPoint * newPoint = new KoPathPoint(this, p);

    qreal angle = m_points[index2]->angle();
    if (inverted)
        angle += M_PI;

    qreal dx = std::cos(angle) * width;
    qreal dy = std::sin(angle) * width;
    newPoint->setControlPoint1(QPointF(p.x() - dx / 2, p.y() - dy / 2));
    newPoint->setControlPoint2(QPointF(p.x() + dx / 2, p.y() + dy / 2));

    insertPoint(newPoint, KoPathPointIndex(0, pointIndex));
}
/**
 * This method simply ensures presence of two points and
 * adds the needed points for self associations.
 */
void AssociationLine::calculateInitialEndPoints()
{
    if (m_associationWidget->isSelf() && count() < 4) {
        for (int i = count(); i < 4; ++i) {
            insertPoint(i, QPointF());
        }
        UMLWidget *wid = m_associationWidget->widgetForRole(Uml::RoleType::B);
        if (!wid) {
            uError() << "AssociationWidget is partially constructed."
                "UMLWidget for role B is null.";
            return;
        }
        const QRectF rect = m_associationWidget->mapFromScene(
                mapToScene(wid->rect()).boundingRect()).boundingRect();

        qreal l = rect.left() + .25 * rect.width();
        qreal r = rect.left() + .75 * rect.width();
        bool drawAbove = rect.top() >= SelfAssociationMinimumHeight;
        qreal y = drawAbove ? rect.top() : rect.bottom();
        qreal yOffset = SelfAssociationMinimumHeight;
        if (drawAbove) {
            yOffset *= -1.0;
        }

        setPoint(0, QPointF(l, y));
        setPoint(1, QPointF(l, y + yOffset));
        setPoint(2, QPointF(r, y + yOffset));
        setPoint(3, QPointF(r, y));
    } else if (!m_associationWidget->isSelf() && count() < 2) {
        setEndPoints(QPointF(), QPointF());
    }
}
Exemplo n.º 8
0
void CQuadTree::insertPoint(int x, int y, int hashvalue)
{
	if (m_root == NULL)
		m_root = new CNode(0, 0, m_rangeX, m_rangeY, 0);

	insertPoint(x, y, hashvalue, m_root);

}
/**
 * For a cubic Bezier curve at least four points are needed.
 * If there are less, the missing points will be created.
 * Note: Implementation is only for two points.
 */
void AssociationLine::createSplinePoints()
{
    if (m_points.size() == 2) {  // create two points
        QPointF p1 = m_points.first();  // start point
        QPointF p2 = m_points.last();   // end point
        qreal dx = p2.x() - p1.x();
        qreal dy = p2.y() - p1.y();
        qreal oneThirdX = 0.33 * dx;
        qreal oneThirdY = 0.33 * dy;
        QPointF c1(p1.x() + oneThirdX,  // control point 1
                   p1.y() - oneThirdY);
        QPointF c2(p2.x() - oneThirdX,  // control point 2
                   p2.y() + oneThirdY);
        insertPoint(1, c1);
        insertPoint(2, c2);
    }
    if (m_points.size() == 3) {  // create one point
        // insertPoint(1 or 2, );
        // Note: For now we use a quadratic Bezier curve in createBezierCurve(...).
    }
}
Exemplo n.º 10
0
U32 OptimizedPolyList::insertVertex(const Point3F& point, const Point3F& normal,
                                    const Point2F& uv0, const Point2F& uv1)
{
   VertIndex vert;

   vert.vertIdx   = insertPoint(point);
   vert.normalIdx = insertNormal(normal);
   vert.uv0Idx    = insertUV0(uv0);
   vert.uv1Idx    = insertUV1(uv1);

   return mVertexList.push_back_unique(vert);
}
Exemplo n.º 11
0
	void init(TRIANGLE * t, int n)
	{
		for(int i = 0; i < n; ++i)
		{
			vec3f v1(t[i].p[0].x,t[i].p[0].y,t[i].p[0].z);
			vec3f v2(t[i].p[1].x,t[i].p[1].y,t[i].p[1].z);
			vec3f v3(t[i].p[2].x,t[i].p[2].y,t[i].p[2].z);



			Tri tri;
			tri.i = insertPoint(v1);
			tri.j = insertPoint(v2);
			tri.k = insertPoint(v3);
			tri.norm = vec3f(t[i].norm.x,t[i].norm.y, t[i].norm.z);
			tris.push_back(tri);

		}

		std::cout << "Inserted " << vecs.size() << " unique points from " << n*3 << "original points\n";
		calcNormals();
	}
Exemplo n.º 12
0
bool shp_polyline::read( FILE * f, int & bytesRead )	
{	
	shape::read( f, bytesRead );

	int type;
	fread(&type,sizeof(int),1,f);

	bytesRead += sizeof(int);
	if(type != API_SHP_POLYLINE)
	{	cout << "Shape type does not match in record."<<endl;
		return false;		
	}
	
	//input Bounding Box
	//Assign Class Variables topLeft && bottomRight
	double mybounds[4];
	fread(mybounds,sizeof(double),4,f);
	bytesRead += sizeof(double)*4;
	topLeft = api_point( mybounds[0], mybounds[3] );
	bottomRight = api_point( mybounds[2], mybounds[1] );

	//input Number of Parts and Number of Points
	int numParts = 0;
	int numPoints = 0;
	fread(&numParts,sizeof(int),1,f);
	bytesRead += sizeof(int);
	fread(&numPoints,sizeof(int),1,f);
	bytesRead += sizeof(int);
	
	//Allocate space for numparts
	int * p_parts = new int[numParts];
	fread(p_parts,sizeof(int),numParts,f);
	bytesRead += sizeof(int)*numParts;
	//Input parts
	for( int j = 0; j < numParts; j++ )
		parts.push_back( p_parts[j] );	
	
	//Input points
	double x,y;
	for(int i=0;i<numPoints;i++)
	{
		fread(&x,sizeof(double),1,f);
		bytesRead += sizeof(double);
		fread(&y,sizeof(double),1,f);
		bytesRead += sizeof(double);
		api_point p(x,y);
		insertPoint( p, i );
	}

	return true;
}
Exemplo n.º 13
0
	int DBTools::insertLine(INOUT Line& line)
	{
		int lineid = getIdByLine(line);
		if(lineid != 0)
			return lineid;
		int from_point,to_point;
		std::vector<Point3D> vPointTemp;
		vPointTemp = line.getPoints();
		//line
		{
			from_point = insertPoint(vPointTemp[0]);
			to_point = insertPoint(vPointTemp[1]);
			std::stringstream ss_from;
			std::stringstream ss_to;
			ss_from<<from_point;
			ss_to<<to_point;

			std::string sql="insert into line(from_point,to_point) values("+ss_from.str()+"," + ss_to.str()+ ");";
			mysql_query(&myCont,sql.c_str());
			lineid = mysql_insert_id(&myCont);
		}
		//shape points
		for(int pcount = 1; pcount<vPointTemp.size()-1;pcount++)
		{
			std::stringstream ss_lineid;
			std::stringstream ss_pointid;
			std::stringstream ss_number;
			ss_lineid<<lineid;
			ss_pointid<<insertPoint(vPointTemp[pcount+1]);
			ss_number<<pcount;

			std::string sql="insert into shape_points(line_id,point_id,sequence_number) values("+ss_lineid.str()+"," + ss_pointid.str() + " ," + ss_number.str()+ ");";
			mysql_query(&myCont,sql.c_str());
		}
			
		line.setId(lineid);
		return lineid;
	}
/*private*/
void
GeometryGraph::addSelfIntersectionNode(int argIndex,
	const Coordinate& coord, int loc)
{
	// if this node is already a boundary node, don't change it
	if (isBoundaryNode(argIndex,coord)) return;
	if (loc==Location::BOUNDARY && useBoundaryDeterminationRule)
	{
		insertBoundaryPoint(argIndex,coord);
	}
	else
	{
		insertPoint(argIndex,coord,loc);
	}
}
Exemplo n.º 15
0
/**
 * Loads AssociationLine information saved in \a qElement XMI element.
 */
bool AssociationLine::loadFromXMI(QDomElement &qElement)
{
    QString layout = qElement.attribute(QLatin1String("layout"), QLatin1String("polyline"));
    m_layout = fromString(layout);

    QDomNode node = qElement.firstChild();

    m_points.clear();

    QDomElement startElement = node.toElement();
    if(startElement.isNull() || startElement.tagName() != QLatin1String("startpoint")) {
        return false;
    }
    QString x = startElement.attribute(QLatin1String("startx"), QLatin1String("0"));
    qreal nX = x.toFloat();
    QString y = startElement.attribute(QLatin1String("starty"), QLatin1String("0"));
    qreal nY = y.toFloat();
    QPointF startPoint(nX, nY);

    node = startElement.nextSibling();
    QDomElement endElement = node.toElement();
    if(endElement.isNull() || endElement.tagName() != QLatin1String("endpoint")) {
        return false;
    }
    x = endElement.attribute(QLatin1String("endx"), QLatin1String("0"));
    nX = x.toFloat();
    y = endElement.attribute(QLatin1String("endy"), QLatin1String("0"));
    nY = y.toFloat();
    QPointF endPoint(nX, nY);
    setEndPoints(startPoint, endPoint);
    QPointF point;
    node = endElement.nextSibling();
    QDomElement element = node.toElement();
    int i = 1;
    while(!element.isNull()) {
        if(element.tagName() == QLatin1String("point")) {
            x = element.attribute(QLatin1String("x"), QLatin1String("0"));
            y = element.attribute(QLatin1String("y"), QLatin1String("0"));
            point.setX(x.toFloat());
            point.setY(y.toFloat());
            insertPoint(i++, point);
        }
        node = element.nextSibling();
        element = node.toElement();
    }

    return true;
}
Exemplo n.º 16
0
	bool DBTools::insertPoints(INOUT std::vector<Point3D>& vPoint)
	{
		int insertid  = 0;
		std::vector<Point3D> vPointTemp = vPoint;
		std::vector<Point3D>::iterator vPointIter = vPointTemp.begin();

		while(vPointIter != vPointTemp.end())
		{
			insertid = insertPoint(*vPointIter);
			if(insertid == 0)
				return false;

			vPointIter++;
		}

		return true;
	}
Exemplo n.º 17
0
		bool shp_polyline::setMembers( std::deque<CString> members )
		{	try
			{	if( members.size() < 3 || ( members.size() - 1 )%2 != 0 )
					throw( Exception("Cannot create shp_polyline ... wrong number of parameters.") );
				if( members[0] != API_SHP_POLYLINE )
					throw( Exception("  Cannot create shp_polyline.  Shape type invalid." ) );
				
				for( int i = 1; i < members.size(); i += 2 )
				{	api_point p;
					p.setX( CStringToDouble( members[i] ) );
					p.setY( CStringToDouble( members[i+1] ) );
					insertPoint( p, 0 );
				}
				return true;
			}
			catch( Exception e )
			{	return false;
			}
		}
/*
 * The left and right topological location arguments assume that the ring
 * is oriented CW.
 * If the ring is in the opposite orientation,
 * the left and right locations must be interchanged.
 */
void
GeometryGraph::addPolygonRing(const LinearRing *lr, int cwLeft, int cwRight)
	// throw IllegalArgumentException (see below)
{
	// skip empty component (see bug #234)
	if ( lr->isEmpty() ) return;

	const CoordinateSequence *lrcl = lr->getCoordinatesRO();

	CoordinateSequence* coord=CoordinateSequence::removeRepeatedPoints(lrcl);
	if (coord->getSize()<4) {
		hasTooFewPointsVar=true;
		invalidPoint=coord->getAt(0); // its now a Coordinate
		delete coord;
		return;
	}
	int left=cwLeft;
	int right=cwRight;

	/*
	 * the isCCW call might throw an
	 * IllegalArgumentException if degenerate ring does
	 * not contain 3 distinct points.
	 */
	try
	{
		if (CGAlgorithms::isCCW(coord)) {
			left=cwRight;
			right=cwLeft;
		}
	}
	catch(...)
	{
		delete coord;
		throw;
	}

	Edge *e=new Edge(coord,new Label(argIndex,Location::BOUNDARY,left,right));
	lineEdgeMap[lr]=e;
	insertEdge(e);
	insertPoint(argIndex,coord->getAt(0), Location::BOUNDARY);
}
Exemplo n.º 19
0
bool LinePath::loadFromXMI( QDomElement & qElement ) {
    QDomNode node = qElement.firstChild();
    QDomElement startElement = node.toElement();
    if( startElement.isNull() || startElement.tagName() != "startpoint" )
        return false;
    QString x = startElement.attribute( "startx", "0" );
    int nX = x.toInt();
    QString y = startElement.attribute( "starty", "0" );
    int nY = y.toInt();
    QPoint startPoint( nX, nY );

    node = startElement.nextSibling();
    QDomElement endElement = node.toElement();
    if( endElement.isNull() || endElement.tagName() != "endpoint" )
        return false;
    x = endElement.attribute( "endx", "0" );
    nX = x.toInt();
    y = endElement.attribute( "endy", "0" );
    nY = y.toInt();
    QPoint endPoint( nX, nY );
    setStartEndPoints( startPoint, endPoint );
    QPoint point;
    node = endElement.nextSibling();
    QDomElement element = node.toElement();
    int i = 1;
    while( !element.isNull() ) {
        if( element.tagName() == "point" ) {
            x = element.attribute( "x", "0" );
            y = element.attribute( "y", "0" );
            point.setX( x.toInt() );
            point.setY( y.toInt() );
            insertPoint( i++, point );
        }
        node = element.nextSibling();
        element = node.toElement();
    }

    return true;
}
void KarbonCalligraphicShape::addCap(int index1, int index2, int pointIndex,
                                     bool inverted)
{
    QPointF p1 = m_points[index1]->point();
    QPointF p2 = m_points[index2]->point();
    qreal width = m_points[index2]->width();

    QPointF direction = QLineF(QPointF(0, 0), p2 - p1).unitVector().p2();
    QPointF p = p2 + direction * m_caps * width;

    KoPathPoint * newPoint = new KoPathPoint(this, p);

    qreal angle = m_points[index2]->angle();
    if (inverted)
        angle += M_PI;

    qreal dx = std::cos(angle) * width;
    qreal dy = std::sin(angle) * width;
    newPoint->setControlPoint1(QPointF(p.x() - dx / 2, p.y() - dy / 2));
    newPoint->setControlPoint2(QPointF(p.x() + dx / 2, p.y() + dy / 2));

    insertPoint(newPoint, KoPathPointIndex(0, pointIndex));
}
Exemplo n.º 21
0
void KdTree::findNearby(Point* p, PointNode* node, int currentBest[], float currentBestDistancesSq[], int& nearbyCount, int axis)
{
	
	insertPoint(p, currentBest, currentBestDistancesSq, nearbyCount, node->p);
	
	float splitCoordDiff = axis == 0 ? p->x - node->p->x : p->y - node->p->y;
	PointNode* primary = splitCoordDiff >= 0 ? node->right : node->left;
	PointNode* secondary = splitCoordDiff >= 0 ? node->left : node->right;
	if(primary)
	{
		findNearby(p, primary, currentBest, currentBestDistancesSq, nearbyCount, (axis + 1) % 2);
	}
	
	
	if(nearbyCount == 0 || splitCoordDiff * splitCoordDiff < currentBestDistancesSq[nearbyCount - 1])
	{
		if(secondary)
		{
			findNearby(p, secondary, currentBest, currentBestDistancesSq, nearbyCount, (axis + 1) % 2);
		}
	}
	
}
Exemplo n.º 22
0
	int DBTools::insertPaint(INOUT Paint& paint)
	{
		Surface sfTemp = paint.getSurface();
		int sfId = insertSurface(sfTemp);

		Point3D pTemp = paint.getLandMark();
		int landmarkId = insertPoint(pTemp);

		std::stringstream ss_surfaceid;
		std::stringstream ss_landmark;
		std::stringstream ss_R;
		std::stringstream ss_G;
		std::stringstream ss_B;
		ss_surfaceid<<sfId;
		ss_landmark<<landmarkId;
		ss_R<<(uint32)paint.getColor().r;
		ss_G<<(uint32)paint.getColor().g;
		ss_B<<(uint32)paint.getColor().b;
		std::string sql="insert into paint(surface_id,landmark_point,color_r,color_g,color_b) values("+ss_surfaceid.str()+ " , " + ss_landmark.str()+ " , " + ss_R.str()+ " , " + ss_G.str()+ " ," + ss_B.str()+ ");";
		mysql_query(&myCont,sql.c_str());
		int paintId = mysql_insert_id(&myCont);
		paint.setId(paintId);
		return paintId;
	}
Exemplo n.º 23
0
	void DBTools::importdatafromNewcoToMaster()
	{
		std::string sql="select * from newco.points;";
		int res=mysql_query(&myCont,sql.c_str());
		if(!res)
		{
			MYSQL_RES *result = mysql_store_result(&myCont);
			if(mysql_num_rows(result))
			{
				MYSQL_ROW sql_row;
				Point3D pTemp;
				while(sql_row=mysql_fetch_row(result))
				{
					pTemp.setId(atoi(sql_row[0]));
					pTemp.setLatitude(atof(sql_row[1]));
					pTemp.setLongitude(atof(sql_row[2]));
					pTemp.setAltitude(atof(sql_row[3]));
					
					insertPoint(pTemp);	
				}
			}
			mysql_free_result(result);
		}
	}
void KarbonCalligraphicShape::
appendPointToPath(const KarbonCalligraphicPoint &p)
{
    qreal dx = std::cos(p.angle()) * p.width();
    qreal dy = std::sin(p.angle()) * p.width();

    // find the outline points
    QPointF p1 = p.point() - QPointF(dx / 2, dy / 2);
    QPointF p2 = p.point() + QPointF(dx / 2, dy / 2);

    if (pointCount() == 0) {
        moveTo(p1);
        lineTo(p2);
        normalize();
        return;
    }
    // pointCount > 0

    bool flip = (pointCount() >= 2) ? flipDetected(p1, p2) : false;

    // if there was a flip add additional points
    if (flip) {
        appendPointsToPathAux(p2, p1);
        if (pointCount() > 4)
            smoothLastPoints();
    }

    appendPointsToPathAux(p1, p2);

    if (pointCount() > 4) {
        smoothLastPoints();

        if (flip) {
            int index = pointCount() / 2;
            // find the last two points
            KoPathPoint *last1 = pointByIndex(KoPathPointIndex(0, index - 1));
            KoPathPoint *last2 = pointByIndex(KoPathPointIndex(0, index));

            last1->removeControlPoint1();
            last1->removeControlPoint2();
            last2->removeControlPoint1();
            last2->removeControlPoint2();
            m_lastWasFlip = true;
        }

        if (m_lastWasFlip) {
            int index = pointCount() / 2;
            // find the previous two points
            KoPathPoint *prev1 = pointByIndex(KoPathPointIndex(0, index - 2));
            KoPathPoint *prev2 = pointByIndex(KoPathPointIndex(0, index + 1));

            prev1->removeControlPoint1();
            prev1->removeControlPoint2();
            prev2->removeControlPoint1();
            prev2->removeControlPoint2();

            if (! flip)
                m_lastWasFlip = false;
        }
    }
    normalize();

    // add initial cap if it's the fourth added point
    // this code is here because this function is called from different places
    // pointCount() == 8 may causes crashes because it doesn't take possible
    // flips into account
    if (m_points.count() >= 4 && &p == m_points[3]) {
        kDebug(38000) << "Adding caps!!!!!!!!!!!!!!!!" << m_points.count();
        addCap(3, 0, 0, true);
        // duplicate the last point to make the points remain "balanced"
        // needed to keep all indexes code (else I would need to change
        // everything in the code...)
        KoPathPoint *last = pointByIndex(KoPathPointIndex(0, pointCount() - 1));
        KoPathPoint *newPoint = new KoPathPoint(this, last->point());
        insertPoint(newPoint, KoPathPointIndex(0, pointCount()));
        close();
    }
}
/*
 * Add a point computed externally.  The point is assumed to be a
 * Point Geometry part, which has a location of INTERIOR.
 */
void
GeometryGraph::addPoint(Coordinate& pt)
{
	insertPoint(argIndex,pt,Location::INTERIOR);
}
Exemplo n.º 26
0
void ImageNavigator::initializeActions() {
    setAttribute(Qt::WA_DeleteOnClose);
    menu = mainMenuBar->addMenu("Focus Viewer");
    QSignalMapper *signalMap = new QSignalMapper(this);

    QAction *showFullScreenAction = new QAction(tr("Show Full Screen"), this);
    showFullScreenAction->setShortcut(tr("Ctrl+F"));
    showFullScreenAction->setCheckable(true);
    connect(showFullScreenAction, SIGNAL(toggled(bool)), this, SLOT(enableFullScreen(bool)));
    menu->addAction(showFullScreenAction);

    toggleInfoToolAction = new QAction(tr("Display Coordinate Info"), this);
    toggleInfoToolAction->setShortcut(tr("I"));
    toggleInfoToolAction->setCheckable(true);
    addAction(toggleInfoToolAction);
    connect(toggleInfoToolAction, SIGNAL(triggered()), this, SLOT(toggleInfoTool()));
    menu->addAction(toggleInfoToolAction);

    // #ifdef Q_OS_MAC
    QMenu *zoomMenu = new QMenu("Zoom", this);
    menu->addMenu(zoomMenu);
    QAction *zoomInAction = new QAction(tr("Zoom In"), this);
    zoomInAction->setShortcut(tr("."));
    addAction(zoomInAction);
    connect(zoomInAction, SIGNAL(triggered()), this, SLOT(zoomIn()));
    zoomMenu->addAction(zoomInAction);

    QAction *zoomOutAction = new QAction(tr("Zoom Out"), this);
    zoomOutAction->setShortcut(tr(","));
    addAction(zoomOutAction);
    connect(zoomOutAction, SIGNAL(triggered()), this, SLOT(zoomOut()));
    zoomMenu->addAction(zoomOutAction);
    QAction *zoomStandardAction = new QAction(tr("Zoom Standard"), this);
    zoomStandardAction->setShortcut(tr("Space"));
    addAction(zoomStandardAction);
    connect(zoomStandardAction, SIGNAL(triggered()), this, SLOT(zoomStandard()));
    zoomMenu->addAction(zoomStandardAction);
    menu->addMenu(zoomMenu);
    //#endif

    toggleColorToolAction = new QAction(tr("Adjust Contrast/Brightness"), this);
    toggleColorToolAction->setShortcut(tr("O"));
    toggleColorToolAction->setCheckable(true);
    addAction(toggleColorToolAction);
    connect(toggleColorToolAction, SIGNAL(triggered()), this, SLOT(toggleColorTool()));
    menu->addAction(toggleColorToolAction);

    // #ifdef Q_OS_MAC
    // CHEN: 4.1.2015
    // if(imageType =="fft")
    // {
    QMenu *brighterMenu = new QMenu("Quick-Adjust Brightness", this);
    menu->addMenu(brighterMenu);
    QAction *brighterAction = new QAction(tr("Brighter"), this);
    brighterAction->setShortcut(tr("b"));
    addAction(brighterAction);
    connect(brighterAction, SIGNAL(triggered()), this, SLOT(brighter()));
    brighterMenu->addAction(brighterAction);

    QAction *darkerAction = new QAction(tr("Darker"), this);
    darkerAction->setShortcut(tr("n"));
    addAction(darkerAction);
    connect(darkerAction, SIGNAL(triggered()), this, SLOT(darker()));
    brighterMenu->addAction(darkerAction);
    // }
    // #endif

    toggleMouseAssignAction = new QAction(tr("Show Mouse Button Assignment"), this);
    toggleMouseAssignAction->setShortcut(tr("M"));
    toggleMouseAssignAction->setCheckable(true);
    addAction(toggleMouseAssignAction);
    connect(toggleMouseAssignAction, SIGNAL(triggered()), this, SLOT(toggleAssignTool()));
    menu->addAction(toggleMouseAssignAction);

    QAction *screenshot = new QAction(tr("Screen Shot"), this);
    screenshot->setShortcut(tr("G"));
    addAction(screenshot);
    connect(screenshot, SIGNAL(triggered()), image, SLOT(grabScreen()));
    menu->addAction(screenshot);

    int projectMode = projectData.projectMode().toInt();

    if (imageType == "fft") {
        viewDisplayParametersAction = new QAction(tr("Display Parameters"), this);
        viewDisplayParametersAction->setShortcut(tr("D"));
        viewDisplayParametersAction->setCheckable(true);
        addAction(viewDisplayParametersAction);
        connect(viewDisplayParametersAction, SIGNAL(triggered()), this, SLOT(toggleDisplayParameters()));
        menu->addAction(viewDisplayParametersAction);

        toggleCTFViewAction = new QAction(tr("View CTF"), this);
        toggleCTFViewAction->setShortcut(tr("C"));
        // toggleCTFViewAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
        toggleCTFViewAction->setCheckable(true);
        addAction(toggleCTFViewAction);
        connect(toggleCTFViewAction, SIGNAL(triggered()), this, SLOT(toggleCTFView()));
        //connect(toggleCTFViewAction,SIGNAL(triggered()),image,SLOT(toggleCTFView()));
        menu->addAction(toggleCTFViewAction);

        if (projectMode == 1) {
            QAction *displayMillerIndicesAction = new QAction(tr("Show Miller Indices"), this);
            displayMillerIndicesAction->setShortcut(tr("Shift+D"));
            displayMillerIndicesAction->setCheckable(true);
            addAction(displayMillerIndicesAction);
            connect(displayMillerIndicesAction, SIGNAL(triggered()), signalMap, SLOT(map()));
            signalMap->setMapping(displayMillerIndicesAction, "millerindices");
            menu->addAction(displayMillerIndicesAction);


            QAction *viewPSPeaksAction = new QAction(tr("View Peak List"), this);
            viewPSPeaksAction->setShortcut(tr("Shift+P"));
            viewPSPeaksAction->setCheckable(true);
            addAction(viewPSPeaksAction);
            connect(viewPSPeaksAction, SIGNAL(triggered()), signalMap, SLOT(map()));
            signalMap->setMapping(viewPSPeaksAction, "pspeaklist");
            connect(signalMap, SIGNAL(mapped(const QString &)), image, SLOT(toggleVisible(const QString &)));
            menu->addAction(viewPSPeaksAction);

            QAction *loadPSPeaksAction = new QAction(tr("Load Peak List"), this);
            loadPSPeaksAction->setShortcut(tr("Shift+L"));
            addAction(loadPSPeaksAction);
            connect(loadPSPeaksAction, SIGNAL(triggered()), this, SLOT(selectPSList()));
            menu->addAction(loadPSPeaksAction);
        }

        QMenu *spotSelection = new QMenu("Spot Selection");
        if (projectMode == 1) menu->addMenu(spotSelection);

        togglePeakListAction = new QAction(tr("Identify Spots"), spotSelection);
        togglePeakListAction->setShortcut(tr("P"));
        togglePeakListAction->setCheckable(true);

        if (projectMode == 1) {
            addAction(togglePeakListAction);
            connect(togglePeakListAction, SIGNAL(triggered()), image, SLOT(togglePeakList()));
            spotSelection->addAction(togglePeakListAction);
        }

        enterSpotSelectionModeAction = new QAction(tr("Enter Spot Selection Mode"), spotSelection);
        enterSpotSelectionModeAction->setCheckable(true);
        enterSpotSelectionModeAction->setShortcut(tr("Ctrl+P"));

        if (projectMode == 1) {
            addAction(enterSpotSelectionModeAction);
            connect(enterSpotSelectionModeAction, SIGNAL(triggered()), this, SLOT(toggleSpotSelectMode()));
            spotSelection->addAction(enterSpotSelectionModeAction);
        }

        savePeakListAction = new QAction(tr("Save Spot List"), spotSelection);
        savePeakListAction->setShortcut(tr("Ctrl+Shift+S"));

        if (projectMode == 1) {
            addAction(savePeakListAction);
            savePeakListAction->setDisabled(true);
            connect(savePeakListAction, SIGNAL(triggered()), image, SLOT(savePeakList()));
            spotSelection->addAction(savePeakListAction);
        }

        loadPeakListAction = new QAction(tr("Reload Spot List"), spotSelection);
        loadPeakListAction->setShortcut(tr("Ctrl+R"));

        if (projectMode == 1) {
            addAction(loadPeakListAction);
            loadPeakListAction->setDisabled(true);
            connect(loadPeakListAction, SIGNAL(triggered()), image, SLOT(loadPeakList()));
            connect(loadPeakListAction, SIGNAL(triggered()), image, SLOT(update()));
            spotSelection->addAction(loadPeakListAction);
        }

        clearPeakListAction = new QAction(tr("Clear Spot List"), spotSelection);
        clearPeakListAction->setShortcut(tr("Ctrl+Shift+C"));

        if (projectMode == 1) {
            addAction(clearPeakListAction);
            clearPeakListAction->setDisabled(true);
            connect(clearPeakListAction, SIGNAL(triggered()), image, SLOT(clearPeakList()));
            spotSelection->addAction(clearPeakListAction);
        }

        QMenu *latticeRefinement = new QMenu("Lattice Refinement");
        if (projectMode == 1) menu->addMenu(latticeRefinement);

        toggleLatticeViewAction = new QAction(tr("View Lattice"), latticeRefinement);
        toggleLatticeViewAction->setShortcut(tr("L"));
        toggleLatticeViewAction->setCheckable(true);
        if (projectMode == 1) {
            addAction(toggleLatticeViewAction);
            connect(toggleLatticeViewAction, SIGNAL(triggered()), image, SLOT(toggleLatticeView()));
            latticeRefinement->addAction(toggleLatticeViewAction);


            QAction *toggleSecondLatticeViewAction = new QAction(tr("View Second Lattice"), latticeRefinement);
            toggleSecondLatticeViewAction->setShortcut(tr("S"));
            toggleSecondLatticeViewAction->setCheckable(true);
            addAction(toggleSecondLatticeViewAction);
            connect(toggleSecondLatticeViewAction, SIGNAL(triggered()), image, SLOT(toggleSecondLatticeView()));
            latticeRefinement->addAction(toggleSecondLatticeViewAction);
        }

        enterLatticeRefinementModeAction = new QAction(tr("Enter Lattice Refinement Mode"), latticeRefinement);
        enterLatticeRefinementModeAction->setShortcut(tr("Shift+R"));
        enterLatticeRefinementModeAction->setCheckable(true);

        if (projectMode == 1) {
            addAction(enterLatticeRefinementModeAction);
            connect(enterLatticeRefinementModeAction, SIGNAL(triggered()), this, SLOT(toggleLatticeRefinementMode()));
            latticeRefinement->addAction(enterLatticeRefinementModeAction);
        }

        addRefinementPointAction = new QAction(tr("Add Refinement Spot"), latticeRefinement);
        addRefinementPointAction->setShortcuts(QList<QKeySequence>() << tr("Enter") << tr("Return"));
        addRefinementPointAction->setEnabled(false);

        if (projectMode == 1) {
            addAction(addRefinementPointAction);
            connect(addRefinementPointAction, SIGNAL(triggered()), latticeTool, SLOT(insertPoint()));
            latticeRefinement->addAction(addRefinementPointAction);
        }

    } else {

        toggleLatticeViewAction = new QAction(tr("View Lattice"), this);
        toggleLatticeViewAction->setShortcut(tr("L"));
        toggleLatticeViewAction->setCheckable(true);

        if (projectMode == 1) {
            addAction(toggleLatticeViewAction);
            menu->addAction(toggleLatticeViewAction);
            connect(toggleLatticeViewAction, SIGNAL(triggered()), signalMap, SLOT(map()));
            signalMap->setMapping(toggleLatticeViewAction, "realLattice");
            connect(signalMap, SIGNAL(mapped(const QString &)), image, SLOT(toggleVisible(const QString &)));
        }

        toggleParticlesViewAction = new QAction(tr("View Particles"), this);
        toggleParticlesViewAction->setShortcut(tr("P"));
        toggleParticlesViewAction->setCheckable(true);

        if (projectMode == 2) {
            addAction(toggleParticlesViewAction);
            menu->addAction(toggleParticlesViewAction);
            connect(toggleParticlesViewAction, SIGNAL(triggered()), image, SLOT(toggleParticleView()));
        }

        QMenu *fftSelectionMenu = new QMenu("Selection based FFT");

        QAction *fftSelectionAction = new QAction(tr("FFT of Selection"), this);
        fftSelectionMenu->addAction(fftSelectionAction);
        fftSelectionAction->setShortcut(tr("Shift+F"));
        fftSelectionAction->setCheckable(true);
        addAction(fftSelectionAction);
        connect(fftSelectionAction, SIGNAL(triggered()), this, SLOT(toggleFFTSelection()));

        if (projectMode == 1) {
            QAction *setReferenceOriginAction = new QAction(tr("Set Reference Origin"), this);
            fftSelectionMenu->addAction(setReferenceOriginAction);
            setReferenceOriginAction->setShortcut(tr("Shift+O"));
            addAction(setReferenceOriginAction);
            connect(setReferenceOriginAction, SIGNAL(triggered()), this, SLOT(setReferenceOrigin()));
            connect(setReferenceOriginAction, SIGNAL(triggered()), spotSelect, SLOT(updateReferenceOrigin()));
        }

        menu->addMenu(fftSelectionMenu);

        selectionMenu = new QMenu("Polygonal Selection");

        if (projectMode == 1) {
            QAction *selectionAreaAction = new QAction(tr("Polygonal Selection Masking"), this);
            selectionMenu->addAction(selectionAreaAction);
            selectionAreaAction->setShortcut(tr("Shift+S"));
            selectionAreaAction->setCheckable(true);
            addAction(selectionAreaAction);
            connect(selectionAreaAction, SIGNAL(triggered()), this, SLOT(toggleCreatePathMode()));


            QAction *saveSelectionArea = new QAction(tr("Save Selection"), this);
            selectionMenu->addAction(saveSelectionArea);
            saveSelectionArea->setShortcut(tr("Ctrl+Shift+S"));
            addAction(saveSelectionArea);
            connect(saveSelectionArea, SIGNAL(triggered()), image, SLOT(saveSelectionList()));

            QAction *clearSelectionArea = new QAction(tr("Clear Selection"), this);
            selectionMenu->addAction(clearSelectionArea);
            clearSelectionArea->setShortcut(tr("Ctrl+Shift+C"));
            addAction(clearSelectionArea);
            connect(clearSelectionArea, SIGNAL(triggered()), image, SLOT(clearSelectionVertices()));

            menu->addMenu(selectionMenu);


            QMenu *referenceMenu = new QMenu("Unbending References", menu);

            QAction *toggleBoxa1Action = new QAction(tr("View Boxa1"), this);
            toggleBoxa1Action->setCheckable(true);
            referenceMenu->addAction(toggleBoxa1Action);
            addAction(toggleBoxa1Action);
            connect(toggleBoxa1Action, SIGNAL(triggered()), this, SLOT(toggleBoxa1()));

            QAction *toggleBoxa2Action = new QAction(tr("View Boxa2"), this);
            toggleBoxa2Action->setCheckable(true);
            referenceMenu->addAction(toggleBoxa2Action);
            addAction(toggleBoxa2Action);
            connect(toggleBoxa2Action, SIGNAL(triggered()), this, SLOT(toggleBoxa2()));

            QAction *toggleBoxb1Action = new QAction(tr("View Boxb1"), this);
            toggleBoxb1Action->setCheckable(true);
            referenceMenu->addAction(toggleBoxb1Action);
            addAction(toggleBoxb1Action);
            connect(toggleBoxb1Action, SIGNAL(triggered()), this, SLOT(toggleBoxb1()));

            QAction *toggleBoxb2Action = new QAction(tr("View Boxb2"), this);
            toggleBoxb2Action->setCheckable(true);
            referenceMenu->addAction(toggleBoxb2Action);
            addAction(toggleBoxb2Action);
            connect(toggleBoxb2Action, SIGNAL(triggered()), this, SLOT(toggleBoxb2()));

            menu->addMenu(referenceMenu);

            QAction *setPhaseOriginAction = new QAction(tr("Set Phase Origin"), this);
            menu->addAction(setPhaseOriginAction);
            setPhaseOriginAction->setShortcut(tr("Shift+P"));
            addAction(setPhaseOriginAction);
            connect(setPhaseOriginAction, SIGNAL(triggered()), this, SLOT(setPhaseOrigin()));
        }

    }

    if (projectMode == 1) {
        QAction *showTiltAxisAction = new QAction(tr("View Tilt Axis in Raw Image (TLTAXIS)"), this);
        menu->addAction(showTiltAxisAction);
        showTiltAxisAction->setCheckable(true);
        showTiltAxisAction->setShortcut(tr("T"));
        addAction(showTiltAxisAction);
        connect(showTiltAxisAction, SIGNAL(triggered()), signalMap, SLOT(map()));
        signalMap->setMapping(showTiltAxisAction, "tiltaxis");
        connect(signalMap, SIGNAL(mapped(const QString &)), image, SLOT(toggleVisible(const QString &)));

        QAction *showTaxisAction = new QAction(tr("View Tilt Axis in Final Map (TAXA)"), this);
        menu->addAction(showTaxisAction);
        showTaxisAction->setCheckable(true);
        showTaxisAction->setShortcut(tr("Shift+T"));
        addAction(showTaxisAction);
        connect(showTaxisAction, SIGNAL(triggered()), signalMap, SLOT(map()));
        signalMap->setMapping(showTaxisAction, "tiltaxa");
        connect(signalMap, SIGNAL(mapped(const QString &)), image, SLOT(toggleVisible(const QString &)));
    }


    QAction *helpAction = new QAction(tr("Help"), this);
    helpAction->setShortcut(tr("H"));
    helpAction->setCheckable(true);
    addAction(helpAction);
    connect(helpAction, SIGNAL(triggered()), this, SLOT(toggleHelp()));
    menu->addAction(helpAction);

    closeAction = new QAction(tr("Close"), this);
    closeAction->setShortcut(tr("Esc"));
    addAction(closeAction);
    connect(closeAction, SIGNAL(triggered()), this, SLOT(closeCurrent()));
    menu->addAction(closeAction);

    //  menuBar->addMenu(menu);
}
Exemplo n.º 27
0
	Cost BL::calc(const int areaW)
	{
		vector<Id> ids = getImageIds();
		sort(ids.begin(), ids.end(), DecreasingNormalWidthCmp(this));

		typedef vector<S> V;
		typedef V::iterator Itr;

		V v;
		v.push_back(S(Point(0, 0), 0, areaW));

		list<Id> idsList(ids.begin(), ids.end());
		while (!idsList.empty())
		{
			Itr insertItr = v.end();
			int bestY = numeric_limits<int>::max();

			//insertItr
			list<Id>::iterator idsListBestItr = idsList.begin();
			for (list<Id>::iterator idsListItr = idsList.begin(); idsListItr != idsList.end(); ++idsListItr)
			{
				const int w = normalWidth(*idsListItr);
				bool wasBetter = false;
				
				//cache friendly
				for (Itr itr = v.begin(); itr != v.end(); ++itr)
				{
					if (itr->left + itr->right >= w && itr->point.y < bestY)
					{
						insertItr = itr;
						bestY = itr->point.y;
						wasBetter = true;
					}
				}
				if (wasBetter)
					idsListBestItr = idsListItr;

				if (!morePrecisie)
					break;
			}

			const Id item = *idsListBestItr;
			idsList.erase(idsListBestItr);

			//init
			const int itemW = normalWidth(item);
			const int itemH = normalHeight(item);

			Point insertPoint(insertItr->point.x - insertItr->left, insertItr->point.y);
			const int insertY1(insertPoint.y);
			const int insertY2(insertY1 + itemH);
			const int insertX1(insertPoint.x);
			const int insertX2(insertX1 + itemW);

			Itr firstCovered = v.begin();
			Itr firstNotCovered = v.end();

			S s1(Point(insertPoint.x, insertPoint.y + itemH), insertPoint.x, areaW - insertPoint.x);
			S s2(Point(insertPoint.x + itemW, insertPoint.y + itemH), insertPoint.x + itemW, areaW - insertPoint.x - itemW);
			S s3(Point(insertPoint.x + itemW, insertPoint.y), 0, areaW - insertPoint.x - itemW);

			//firstCovered
			firstCovered = insertItr;
			for (Itr itr = v.begin(); itr != v.end(); ++itr)
			{
				if (insertX1 <= itr->point.x && itr->point.x <= insertX2 && itr->point.y <= insertY2)
				{
					firstCovered = itr;
					break;					
				}
			}

			//firstNotCovered
			for (Itr itr = v.begin(); itr != v.end(); ++itr)
			{
				if (insertX2 <= itr->point.x)
				{
					firstNotCovered = itr;
					break;
				}
			}

			//correct existing items
			for (Itr itr = v.begin(); itr != v.end(); ++itr)
			{
			    if (itr->point.y < insertY2) 
				{
					if (itr->point.x <= insertX1)
					{
						int newRight = insertX1 - itr->point.x;
						if (newRight < itr->right)
							itr->right = newRight;
					}
					else if (insertX2 <= itr->point.x)
					{
						int newLeft = itr->point.x - insertX2;
						if (newLeft < itr->left)
							itr->left = newLeft;
					}
				}
			}

			//s1.left
			for (Itr itr = firstCovered; ;)
			{
				if (itr->point.y > s1.point.y)
				{
					s1.left = s1.point.x - itr->point.x;
					break;
				}

				if (itr == v.begin())
					break;

				--itr;
			}

			//s1.right
			for (Itr itr = firstNotCovered; itr != v.end(); ++itr)
			{
				if (itr->point.y > s1.point.y)
				{
					s1.right = itr->point.x - s1.point.x;
					break;
				}
			}

			//s2.left
			s2.left = s1.left + itemW;

			//s2.right
			s2.right = s1.right - itemW;

			//s3.right
			for (Itr itr = firstNotCovered; itr != v.end(); ++itr)
			{
				if (itr->point.y > s3.point.y)
				{
					s3.right = itr->point.x - s3.point.x;
					break;
				}
			}

			//insert item
			result.add(item, normalPoint(insertPoint));

			//reconstruction
			V v2;

			for (Itr itr = v.begin(); itr != firstCovered; ++itr)
				v2.push_back(*itr);

			v2.push_back(s1);
			v2.push_back(s2);
			v2.push_back(s3);

			for (Itr itr = firstNotCovered; itr != v.end(); ++itr)
				v2.push_back(*itr);

			v = v2;
		}

		checkForCollisions();

		return calcResultCost();
	}
Exemplo n.º 28
0
    void MeshChunk::InsertWater(int x, int y, int z, float portionParType){
        float portionOfBlockInTexture_Y = 0.f;
        float portionOfBlockInTexture_Y_PLUSONE = portionParType;
        // TOP
        if(getVal(x,y+1,z) == 0){
            insertPoint(division_1_sur_3, portionOfBlockInTexture_Y_PLUSONE, x+1.0f, y+1.0f, z, 0.f, 1.f, 0.f);
            insertPoint(0.f, portionOfBlockInTexture_Y_PLUSONE, x, y+1.0f, z, 0.f, 1.f, 0.f);

            insertPoint(0.f, portionOfBlockInTexture_Y, x, y+1.0f, z+1.0f, 0.f, 1.f, 0.f);
            insertPoint(0.f, portionOfBlockInTexture_Y, x, y+1.0f, z+1.0f, 0.f, 1.f, 0.f);

            insertPoint(division_1_sur_3, portionOfBlockInTexture_Y, x+1.f, y+1.f, z+1.0f, 0.f, 1.f, 0.f);
            insertPoint(division_1_sur_3, portionOfBlockInTexture_Y_PLUSONE, x+1.f, y+1.0f, z, 0.f, 1.f, 0.f);
        }
        // BOTTOM
        if(getVal(x,y-1,z) == 0){        
            insertPoint(1, portionOfBlockInTexture_Y_PLUSONE, x+1.0f, y, z+1.0f, 0.f, -1.f, 0.f);
            insertPoint(division_2_sur_3, portionOfBlockInTexture_Y_PLUSONE, x, y, z+1.0f, 0.f, -1.f, 0.f);

            insertPoint(division_2_sur_3, portionOfBlockInTexture_Y, x, y, z, 0.f, -1.f, 0.f);
            insertPoint(division_2_sur_3, portionOfBlockInTexture_Y, x, y, z, 0.f, -1.f, 0.f);

            insertPoint(1, portionOfBlockInTexture_Y, x+1.f, y, z, 0.f, -1.f, 0.f);
            insertPoint(1, portionOfBlockInTexture_Y_PLUSONE, x+1.f, y, z+1.f, 0.f, -1.f, 0.f);
        }
        // LEFT
        if(getVal(x-1,y,z) == 0){
            insertPoint(1, portionOfBlockInTexture_Y_PLUSONE, x, y, z, -1.f, 0.f, 0.f);
            insertPoint(division_2_sur_3, portionOfBlockInTexture_Y_PLUSONE, x, y, z+1.f, -1.f, 0.f, 0.f);

            insertPoint(division_2_sur_3, portionOfBlockInTexture_Y, x, y+1.f, z+1.f, -1.f, 0.f, 0.f);
            insertPoint(division_2_sur_3, portionOfBlockInTexture_Y, x, y+1.f, z+1.f, -1.f, 0.f, 0.f);

            insertPoint(1, portionOfBlockInTexture_Y, x, y+1.f, z, -1.f, 0.f, 0.f);
            insertPoint(1, portionOfBlockInTexture_Y_PLUSONE, x, y, z, -1.f, 0.f, 0.f);
        }
        // RIGHT
        if(getVal(x+1,y,z) == 0){
            insertPoint(1, portionOfBlockInTexture_Y_PLUSONE, x+1.f, y, z+1.f, 1.f, 0.f, 0.f);
            insertPoint(division_2_sur_3, portionOfBlockInTexture_Y_PLUSONE, x+1.f, y, z, 1.f, 0.f, 0.f);

            insertPoint(division_2_sur_3, portionOfBlockInTexture_Y, x+1.f, y+1.f, z, 1.f, 0.f, 0.f);
            insertPoint(division_2_sur_3, portionOfBlockInTexture_Y, x+1.f, y+1.f, z, 1.f, 0.f, 0.f);

            insertPoint(1, portionOfBlockInTexture_Y, x+1.f, y+1.f, z+1.f, 1.f, 0.f, 0.f);
            insertPoint(1, portionOfBlockInTexture_Y_PLUSONE, x+1.f, y, z+1.f, 1.f, 0.f, 0.f);
        }
        // BACK
        if(getVal(x,y,z+1) == 0){
            insertPoint(1, portionOfBlockInTexture_Y_PLUSONE, x, y, z+1.f, 0.f, 0.f, 1.f);
            insertPoint(division_2_sur_3, portionOfBlockInTexture_Y_PLUSONE, x+1.f, y, z+1.f, 0.f, 0.f, 1.f);

            insertPoint(division_2_sur_3, portionOfBlockInTexture_Y, x+1.f, y+1.f, z+1.f, 0.f, 0.f, 1.f);
            insertPoint(division_2_sur_3, portionOfBlockInTexture_Y, x+1.f, y+1.f, z+1.f, 0.f, 0.f, 1.f);

            insertPoint(1, portionOfBlockInTexture_Y, x, y+1.f, z+1.f, 0.f, 0.f, 1.f);
            insertPoint(1, portionOfBlockInTexture_Y_PLUSONE, x, y, z+1.f, 0.f, 0.f, 1.f);
        }
        // FRONT
        if(getVal(x,y+1,z) == 0){
            insertPoint(1, portionOfBlockInTexture_Y_PLUSONE, x+1.f, y, z, 0.f, 0.f, -1.f);
            insertPoint(division_2_sur_3, portionOfBlockInTexture_Y_PLUSONE, x, y, z, 0.f, 0.f, -1.f);

            insertPoint(division_2_sur_3, portionOfBlockInTexture_Y, x, y+1.f, z, 0.f, 0.f, -1.f);
            insertPoint(division_2_sur_3, portionOfBlockInTexture_Y, x, y+1.f, z, 0.f, 0.f, -1.f);

            insertPoint(1, portionOfBlockInTexture_Y, x+1.f, y+1.f, z, 0.f, 0.f, -1.f);
            insertPoint(1, portionOfBlockInTexture_Y_PLUSONE, x+1.f, y, z, 0.f, 0.f, -1.f);
        }
    }
Exemplo n.º 29
0
    void MeshChunk::build(){       
        int m_width = 16;//land.getWidthMax();
        int m_height = 128;//land.getHeightMax();
        int m_deep = 16;//land.getDeepMax();

        int nbTextureMax = 8; // nombre de type different max sur notre texture, a faire evoluer pour de la dynamique

        float portionParType = 1.f/(float)nbTextureMax;

        m_nVertexCount = 0;

        for (int x = 0; x < m_width; ++x){
            for (int y = 0; y < m_height; ++y){
                for (int z = 0; z < m_deep; ++z){
                    if(getVal(x,y,z) > 0 && getVisible(x,y,z) > 0){
                        int typeOfBlock = getVal(x,y,z) - 1;
                        float portionOfBlockInTexture_Y = typeOfBlock*portionParType;
                        float portionOfBlockInTexture_Y_PLUSONE = portionOfBlockInTexture_Y+portionParType;

                        bool visibilityTop = checkFaceVisibility_top(x, y, z);
                        if(visibilityTop){
                            // TOP
                            insertPoint(division_1_sur_3, portionOfBlockInTexture_Y_PLUSONE, x+1.0f, y+1.0f, z, 0.f, 1.f, 0.f);
                            insertPoint(0.f, portionOfBlockInTexture_Y_PLUSONE, x, y+1.0f, z, 0.f, 1.f, 0.f);

                            insertPoint(0.f, portionOfBlockInTexture_Y, x, y+1.0f, z+1.0f, 0.f, 1.f, 0.f);
                            insertPoint(0.f, portionOfBlockInTexture_Y, x, y+1.0f, z+1.0f, 0.f, 1.f, 0.f);

                            insertPoint(division_1_sur_3, portionOfBlockInTexture_Y, x+1.f, y+1.f, z+1.0f, 0.f, 1.f, 0.f);
                            insertPoint(division_1_sur_3, portionOfBlockInTexture_Y_PLUSONE, x+1.f, y+1.0f, z, 0.f, 1.f, 0.f);
                        }
                        if(checkFaceVisibility_bottom(x, y, z)){
                        // BOTTOM
                            insertPoint(1, portionOfBlockInTexture_Y_PLUSONE, x+1.0f, y, z+1.0f, 0.f, -1.f, 0.f);
                            insertPoint(division_2_sur_3, portionOfBlockInTexture_Y_PLUSONE, x, y, z+1.0f, 0.f, -1.f, 0.f);

                            insertPoint(division_2_sur_3, portionOfBlockInTexture_Y, x, y, z, 0.f, -1.f, 0.f);
                            insertPoint(division_2_sur_3, portionOfBlockInTexture_Y, x, y, z, 0.f, -1.f, 0.f);

                            insertPoint(1, portionOfBlockInTexture_Y, x+1.f, y, z, 0.f, -1.f, 0.f);
                            insertPoint(1, portionOfBlockInTexture_Y_PLUSONE, x+1.f, y, z+1.f, 0.f, -1.f, 0.f);
                        }
                        if(checkFaceVisibility_left(x, y, z)){
                            // LEFT
                            if(!visibilityTop && getVal(x,y,z) == 4){
                                insertPoint(1, portionOfBlockInTexture_Y_PLUSONE, x, y, z, -1.f, 0.f, 0.f);
                                insertPoint(division_2_sur_3, portionOfBlockInTexture_Y_PLUSONE, x, y, z+1.f, -1.f, 0.f, 0.f);

                                insertPoint(division_2_sur_3, portionOfBlockInTexture_Y, x, y+1.f, z+1.f, -1.f, 0.f, 0.f);
                                insertPoint(division_2_sur_3, portionOfBlockInTexture_Y, x, y+1.f, z+1.f, -1.f, 0.f, 0.f);

                                insertPoint(1, portionOfBlockInTexture_Y, x, y+1.f, z, -1.f, 0.f, 0.f);
                                insertPoint(1, portionOfBlockInTexture_Y_PLUSONE, x, y, z, -1.f, 0.f, 0.f);
                            }else{
                                insertPoint(division_2_sur_3, portionOfBlockInTexture_Y_PLUSONE, x, y, z, -1.f, 0.f, 0.f);
                                insertPoint(division_1_sur_3, portionOfBlockInTexture_Y_PLUSONE, x, y, z+1.f, -1.f, 0.f, 0.f);

                                insertPoint(division_1_sur_3, portionOfBlockInTexture_Y, x, y+1.f, z+1.f, -1.f, 0.f, 0.f);
                                insertPoint(division_1_sur_3, portionOfBlockInTexture_Y, x, y+1.f, z+1.f, -1.f, 0.f, 0.f);

                                insertPoint(division_2_sur_3, portionOfBlockInTexture_Y, x, y+1.f, z, -1.f, 0.f, 0.f);
                                insertPoint(division_2_sur_3, portionOfBlockInTexture_Y_PLUSONE, x, y, z, -1.f, 0.f, 0.f);
                            }
                        }
                        if(checkFaceVisibility_right(x, y, z)){
                            // RIGHT
                            if(!visibilityTop && getVal(x,y,z) == 4){
                                insertPoint(1, portionOfBlockInTexture_Y_PLUSONE, x+1.f, y, z+1.f, 1.f, 0.f, 0.f);
                                insertPoint(division_2_sur_3, portionOfBlockInTexture_Y_PLUSONE, x+1.f, y, z, 1.f, 0.f, 0.f);

                                insertPoint(division_2_sur_3, portionOfBlockInTexture_Y, x+1.f, y+1.f, z, 1.f, 0.f, 0.f);
                                insertPoint(division_2_sur_3, portionOfBlockInTexture_Y, x+1.f, y+1.f, z, 1.f, 0.f, 0.f);

                                insertPoint(1, portionOfBlockInTexture_Y, x+1.f, y+1.f, z+1.f, 1.f, 0.f, 0.f);
                                insertPoint(1, portionOfBlockInTexture_Y_PLUSONE, x+1.f, y, z+1.f, 1.f, 0.f, 0.f);
                            }else{
                                insertPoint(division_2_sur_3, portionOfBlockInTexture_Y_PLUSONE, x+1.f, y, z+1.f, 1.f, 0.f, 0.f);
                                insertPoint(division_1_sur_3, portionOfBlockInTexture_Y_PLUSONE, x+1.f, y, z, 1.f, 0.f, 0.f);

                                insertPoint(division_1_sur_3, portionOfBlockInTexture_Y, x+1.f, y+1.f, z, 1.f, 0.f, 0.f);
                                insertPoint(division_1_sur_3, portionOfBlockInTexture_Y, x+1.f, y+1.f, z, 1.f, 0.f, 0.f);

                                insertPoint(division_2_sur_3, portionOfBlockInTexture_Y, x+1.f, y+1.f, z+1.f, 1.f, 0.f, 0.f);
                                insertPoint(division_2_sur_3, portionOfBlockInTexture_Y_PLUSONE, x+1.f, y, z+1.f, 1.f, 0.f, 0.f);
                            }
                        }
                        if(checkFaceVisibility_back(x, y, z)){
                            // BACK
                            if(!visibilityTop && getVal(x,y,z) == 4){
                                insertPoint(1, portionOfBlockInTexture_Y_PLUSONE, x, y, z+1.f, 0.f, 0.f, 1.f);
                                insertPoint(division_2_sur_3, portionOfBlockInTexture_Y_PLUSONE, x+1.f, y, z+1.f, 0.f, 0.f, 1.f);

                                insertPoint(division_2_sur_3, portionOfBlockInTexture_Y, x+1.f, y+1.f, z+1.f, 0.f, 0.f, 1.f);
                                insertPoint(division_2_sur_3, portionOfBlockInTexture_Y, x+1.f, y+1.f, z+1.f, 0.f, 0.f, 1.f);

                                insertPoint(1, portionOfBlockInTexture_Y, x, y+1.f, z+1.f, 0.f, 0.f, 1.f);
                                insertPoint(1, portionOfBlockInTexture_Y_PLUSONE, x, y, z+1.f, 0.f, 0.f, 1.f);
                            }else{
                                insertPoint(division_2_sur_3, portionOfBlockInTexture_Y_PLUSONE, x, y, z+1.f, 0.f, 0.f, 1.f);
                                insertPoint(division_1_sur_3, portionOfBlockInTexture_Y_PLUSONE, x+1.f, y, z+1.f, 0.f, 0.f, 1.f);

                                insertPoint(division_1_sur_3, portionOfBlockInTexture_Y, x+1.f, y+1.f, z+1.f, 0.f, 0.f, 1.f);
                                insertPoint(division_1_sur_3, portionOfBlockInTexture_Y, x+1.f, y+1.f, z+1.f, 0.f, 0.f, 1.f);

                                insertPoint(division_2_sur_3, portionOfBlockInTexture_Y, x, y+1.f, z+1.f, 0.f, 0.f, 1.f);
                                insertPoint(division_2_sur_3, portionOfBlockInTexture_Y_PLUSONE, x, y, z+1.f, 0.f, 0.f, 1.f);
                            }
                        }
                        if(checkFaceVisibility_front(x, y, z)){
                            // FRONT
                            if(!visibilityTop && getVal(x,y,z) == 4){
                                insertPoint(1, portionOfBlockInTexture_Y_PLUSONE, x+1.f, y, z, 0.f, 0.f, -1.f);
                                insertPoint(division_2_sur_3, portionOfBlockInTexture_Y_PLUSONE, x, y, z, 0.f, 0.f, -1.f);

                                insertPoint(division_2_sur_3, portionOfBlockInTexture_Y, x, y+1.f, z, 0.f, 0.f, -1.f);
                                insertPoint(division_2_sur_3, portionOfBlockInTexture_Y, x, y+1.f, z, 0.f, 0.f, -1.f);

                                insertPoint(1, portionOfBlockInTexture_Y, x+1.f, y+1.f, z, 0.f, 0.f, -1.f);
                                insertPoint(1, portionOfBlockInTexture_Y_PLUSONE, x+1.f, y, z, 0.f, 0.f, -1.f);
                            }else{
                                insertPoint(division_2_sur_3, portionOfBlockInTexture_Y_PLUSONE, x+1.f, y, z, 0.f, 0.f, -1.f);
                                insertPoint(division_1_sur_3, portionOfBlockInTexture_Y_PLUSONE, x, y, z, 0.f, 0.f, -1.f);

                                insertPoint(division_1_sur_3, portionOfBlockInTexture_Y, x, y+1.f, z, 0.f, 0.f, -1.f);
                                insertPoint(division_1_sur_3, portionOfBlockInTexture_Y, x, y+1.f, z, 0.f, 0.f, -1.f);

                                insertPoint(division_2_sur_3, portionOfBlockInTexture_Y, x+1.f, y+1.f, z, 0.f, 0.f, -1.f);
                                insertPoint(division_2_sur_3, portionOfBlockInTexture_Y_PLUSONE, x+1.f, y, z, 0.f, 0.f, -1.f);
                            }
                        }
                    }//else if(getVal(x,y,z) == 1){
                    //     InsertWater(x, y, z, portionParType);
                    // }
                }
            }
        }


        m_pDataPointer = new ShapeVertex[m_nVertexCount];

        for (int i = 0; i < m_nVertexCount; ++i){
            m_pDataPointer[i] = temporaryVector.at(i);
        }

        temporaryVector.clear();
        cubeDataVector.clear();
    }
Exemplo n.º 30
0
 //! Inserts the min- and max points of the given box to this bounding box. This can result in that the box becomes larger.
 force_inline void insertBox(const aabbox3d<T> &Other)
 {
     insertPoint(Other.Min);
     insertPoint(Other.Max);
 }