void _TBOX_PREFIX_App::drawPcmData()
{
    if ( mPcmBuffer.isEmpty() )
        return;
    
    // draw the first(left) channel in the PCM buffer
    // getData() returns a pointer to the first sample in the buffer
	uint32_t    bufferLength    = mPcmBuffer.getSize() / mPcmBuffer.getNumChannels();
    float       *leftBuffer     = mPcmBuffer.getData();

	int     displaySize = getWindowWidth();
	float   scale       = displaySize / (float)bufferLength;

	PolyLine<Vec2f>	leftBufferLine;

    gl::color( Color::gray( 0.4f ) );
	
	for( int i = 0; i < bufferLength; i++ )
    {
		float x = i * scale;
        float y = 50 + leftBuffer[i] * 60;
		leftBufferLine.push_back( Vec2f( x , y) );
	}

	gl::draw( leftBufferLine );
}
Beispiel #2
0
  void defineShapes(Shapes *S) {
    // simplify contours
    vector<vector<Point> > contours_poly( contours.size() ); 
    for( int i = 0; i< contours.size(); i++ ) {
      approxPolyDP( Mat(contours[i]), contours_poly[i], 1.1, true ); 
    }

    RNG rng(12345);
    for( int i = 0; i< contours.size(); i++ ) {
      PolyLine *PL = new PolyLine();
      PL->setPenColor(0,0,0);
      if (use_random_colors) { PL->setPenColor(rng.uniform(100,200),rng.uniform(100,200),rng.uniform(100,200)); }

      if (contours_poly[i].size()>min_contour_length) {
	// printf("Contour:%i [%lu points]\n",i,contours_poly[i].size());
	for (int j=0; j<contours_poly[i].size();j++) {
	  //printf("(%i,%i)",contours[i][j].x,contours[i][j].y);
	  //if (j!=contours_poly[i].size()-1) { printf(","); }
	  PL->addPoint(contours_poly[i][j].x,contours_poly[i][j].y);
	}
	S->addShape(PL);
	//printf("\n");
      }
    }
  }
// Draw
void KissTempoApp::draw()
{

	// Clear screen
	gl::clear( ColorAf::black() );

	// Check sizes
	if ( mDataSize > 0 && mWaveform.size() > 0 ) {

		// Get dimensions
		float windowWidth = (float)getWindowWidth();
		float center = windowWidth * 0.5f;

		// Draw waveform
		float y = 0.0f;
		PolyLine<Vec2f> mLine;
		uint32_t ampCount = mWaveform.size();
		for ( uint32_t i = 0; i < ampCount; i++, y += 6.5f ) {
			float x = mWaveform[ i ] * windowWidth;
			mLine.push_back( Vec2f( center + x, y ) );
			mLine.push_back( Vec2f( center - x, y + 3.25f ) );
		}
		gl::draw( mLine );

	}

	// Draw tempo (scale text to improve quality)
	gl::pushMatrices();
	gl::scale( 0.25f, 0.25f );
	mFont->drawString( toString( (int32_t)math<float>::ceil( mTempo ) ) + " BPM", Vec2f( 20.0f * 4.0f, 540.0f * 4.0f ) );
	gl::scale( 0.5f, 0.5f );
	mFont->drawString( "Press SPACE to reset track", Vec2f( 20.0f * 8.0f, 575.0f * 8.0f ) );
	gl::popMatrices();

}
void SoundScapingApp::drawWaveForm() {	
	//if the buffer is null, for example if this gets called before any PCM data has been buffered
	//don't do anything
	if( ! mPcmBuffer ) {
		return;
	}
	
	uint32_t bufferLength = mPcmBuffer->getSampleCount();
	audio::Buffer32fRef leftBuffer = mPcmBuffer->getChannelData( audio::CHANNEL_FRONT_LEFT );
	audio::Buffer32fRef rightBuffer = mPcmBuffer->getChannelData( audio::CHANNEL_FRONT_RIGHT );
    
	int displaySize = getWindowWidth();
	float scale = displaySize / (float)bufferLength;
	
	PolyLine<Vec2f>	leftBufferLine;
	PolyLine<Vec2f>	rightBufferLine;
	
	for( int i = 0; i < bufferLength; i++ ) {
		float x = ( i * scale );
        
		//get the PCM value from the left channel buffer
		float y = ( ( leftBuffer->mData[i] - 1 ) * - 100 );
		leftBufferLine.push_back( Vec2f( x , y) );
		
		y = ( ( rightBuffer->mData[i] - 1 ) * - 100 );
		rightBufferLine.push_back( Vec2f( x , y) );
	}
	gl::color( Color( 0.0f, 0.5f, 1.0f ) );
	gl::draw( leftBufferLine );
	gl::draw( rightBufferLine );
	
}
BOOL SplineData::HitTestSpline(GraphicsWindow *gw,HitRegion *hr, int &hitSplineIndex, float &u)
{
	DWORD limit = gw->getRndLimits();
	gw->setRndLimits(( limit | GW_PICK) & ~GW_ILLUM);
	//loop through splines
	gw->setTransform(Matrix3(1));
	int numLines = mShapeCache.numLines;
	gw->setHitRegion(hr);
	gw->clearHitCode();
	
	for (int splineIndex = 0; splineIndex < numLines;splineIndex++)
	{
		if (mSplineElementData[splineIndex]->IsSelected())
		{		
			PolyLine *line = &mShapeCache.lines[splineIndex];
			Point3 plist[2];
			
			u = 0.0f;		
			for (int i = 0; i < 100; i++)
			{
				plist[0] = line->InterpCurve3D(u,POLYSHP_INTERP_NORMALIZED);
				plist[1] = line->InterpCurve3D(u+0.01f,POLYSHP_INTERP_NORMALIZED);
				u += 0.01f;
				gw->polyline(2, plist, NULL, NULL, 0);
				if (gw->checkHitCode()) 
				{
					hitSplineIndex = splineIndex;
					return TRUE;
				}
			}
		}
	}

	return FALSE;
}
Beispiel #6
0
	void draw()
	{
		glPushMatrix();
		
		gl::translate(pos);
		
		gl::color(TILECOLOR);
		
		gl::draw(*hex);
		
		gl::color(TILECOLOR2);
		
		glBegin(GL_TRIANGLE_FAN);
		
		PolyLine<Vec2f>::iterator pt;
		
		for(pt = hex->begin(); pt < hex->end(); pt++)
		{
			gl::vertex(*pt);
		}
		
		glEnd();
		
		/*
		 gl::color(Color(1.0f, .0f, .0f));
		 for(pt = hex->begin(); pt < hex->end() - 1; pt++)
		 {
		 gl::vertex(*pt);
		 }
		 */
		
		for(int i = 0; i < 6; i++)
		{
			if(connections[i])
			{
				Vec2f v = (connections[i]->pos - pos)/2.0f;
				gl::color(Color(.0f, 1.0f, .0f));
				gl::drawLine(Vec2f(.0f, .0f), v);
			}
			
			if(state[i])
			{
				Vec2f p = cart(TILERAD_MIN - 2.0f, -M_PI/2 - i * M_PI/3.0f);
				gl::color(Color(1.0f, .0f, .0f));
				//				gl::drawSolidCircle(p, 5.0f, 32);
				Vec2f pnorm = p.normalized();
				pnorm.rotate(-M_PI/2.0f);
				
				Vec2f p0 = p - 22.0f * pnorm;
				Vec2f p1 = p + 22.0f * pnorm;
				gl::drawLine(p0, p1);
			}
		}
		
		glPopMatrix();
	}
void PixarDemo2012::generateWaveforms()
{
    // DRAW MEM SPEHRES AND WAVEFORMS
    // Check init flag
    if ( mFft ) {

        // Get data in the frequency (transformed) and time domains
        float * freqData = mFft->getAmplitude();
        float * timeData = mFft->getData();
        int32_t dataSize = mFft->getBinSize();

        // Cast data size to float
        float dataSizef = (float)dataSize;

        // Get dimensions
        float scale = ( (float)getWindowWidth() - 20.0f ) / dataSizef;
        float windowHeight = (float)getWindowHeight();

        // Use polylines to depict time and frequency domains
        PolyLine<Vec2f> freqLine;
        PolyLine<Vec2f> timeLine;

        makeBall = 0.0f;
        float greatestFreq = 0.0;
        // Iterate through data
        for ( int32_t i = 0; i < dataSize; i++ ) {

            // Do logarithmic plotting for frequency domain
            float logSize = math<float>::log( dataSizef );
            float x = (float)( ( math<float>::log( (float)i ) / logSize ) * dataSizef );
            float y = math<float>::clamp( freqData[ i ] * ( x / dataSizef ) * ( math<float>::log( ( dataSizef - (float)i ) ) ), 0.0f, 2.0f );

            if (y > makeBall) makeBall = y;

            if(y > greatestFreq)
                greatestFreq = y;


            // Plot points on lines for tme domain
            freqLine.push_back( Vec2f(        x * scale + 10.0f,            -y * ( windowHeight - 20.0f ) * 1.75f + ( windowHeight - 10.0f ) ) );
            timeLine.push_back( Vec2f( (float)i * scale + 10.0f, timeData[ i ] * ( windowHeight - 20.0f ) * 0.25f + ( windowHeight * 0.25f + 10.0f ) ) );

        }
        //printf("%f\n", greatestFreq);
        theMindField.SetAmps(greatestFreq);
        // Draw signals
        if ( drawFFT ) {
            gl::draw( freqLine );
            gl::draw( timeLine );
        }

    }

}
// Draw
void KissBasicApp::draw()
{

	// Clear screen
	gl::clear( ColorAf::black() );

	// Check init flag
	if ( mFft ) {

		// Get data in the frequency (transformed) and time domains
		float * freqData = mFft->getAmplitude();
		float * timeData = mFft->getData();
		int32_t dataSize = mFft->getBinSize();

		// Cast data size to float
		float dataSizef = (float)dataSize;

		// Get dimensions
		float scale = ( (float)getWindowWidth() - 20.0f ) / dataSizef;
		float windowHeight = (float)getWindowHeight();

		// Use polylines to depict time and frequency domains
		PolyLine<Vec2f> freqLine;
		PolyLine<Vec2f> timeLine;

		// Iterate through data
		for ( int32_t i = 0; i < dataSize; i++ ) {

			// Do logarithmic plotting for frequency domain
			float logSize = math<float>::log( dataSizef );
			float x = (float)( (math<float>::log( (float)i) / logSize ) * dataSizef );
			float y = math<float>::clamp( freqData[i] * ( x / dataSizef ) * ( math<float>::log( ( dataSizef - (float)i ) ) ), 0.0f, 2.0f );

			// Plot points on lines for tme domain
			freqLine.push_back( Vec2f(        x * scale + 10.0f,          -y   * ( windowHeight - 20.0f ) * 0.25f + ( windowHeight - 10.0f ) ) );
			timeLine.push_back( Vec2f( (float)i * scale + 10.0f, timeData[ i ] * ( windowHeight - 20.0f ) * 0.25f + ( windowHeight * 0.25f + 10.0f ) ) );

		}

		// Draw signals
		gl::draw( freqLine );
		gl::draw( timeLine );

	}

}
// Draw
void KissFileSampleApp::draw()
{

	// Clear screen
	gl::clear(Color(0.0f, 0.0f, 0.0f));

	// Check init flag
	if (mFftInit)
	{

		// Get data
		float * mFreqData = mFft.getAmplitude();
		float * mTimeData = mFft.getData();
		int32_t mDataSize = mFft.getBinSize();

		// Get dimensions
		float mScale = ((float)getWindowWidth() - 20.0f) / (float)mDataSize;
		float mWindowHeight = (float)getWindowHeight();

		// Use polylines to depict time and frequency domains
		PolyLine<Vec2f> mFreqLine;
		PolyLine<Vec2f> mTimeLine;

		// Iterate through data
		for (int32_t i = 0; i < mDataSize; i++) 
		{

			// Do logarithmic plotting for frequency domain
			double mLogSize = log((double)mDataSize);
			float x = (float)(log((double)i) / mLogSize) * (double)mDataSize;
			float y = math<float>::clamp(mFreqData[i] * (x / mDataSize) * log((double)(mDataSize - i)), 0.0f, 2.0f);

			// Plot points on lines
			mFreqLine.push_back(Vec2f(x * mScale + 10.0f,           -y * (mWindowHeight - 20.0f) * 1.25f + (mWindowHeight - 10.0f)));
			mTimeLine.push_back(Vec2f(i * mScale + 10.0f, mTimeData[i] * (mWindowHeight - 20.0f) * 0.3f  + (mWindowHeight * 0.15f + 10.0f)));

		}

		// Draw signals
		gl::draw(mFreqLine);
		gl::draw(mTimeLine);

	}

}
Beispiel #10
0
void redEyeApp::drawSpectrum(bool fill) {
    if(!mFftLeft) {
        return;
    }
    float *fftBuffer= mFftLeft.get();
    float w= getWindowWidth();
    float a= getWindowHeight()*0.01f;    //spectrum scale
    uint32_t fftSize= mBufferSize/2;
    PolyLine<Vec2f>	line;
    for(uint32_t i= 0; i<fftSize; i++) {
        float x= (i/(float)(fftSize-1))*w-(w*0.5f);
        float y= fftBuffer[i]*a;
        line.push_back(Vec2f(x, 0.0f-y));
        if(fill) {
            line.push_back(Vec2f(x, y));
        }
    }
    gl::draw(line);
}
void shader02vertexApp::drawWaveform(bool fill) {
    if(!mPcmBuffer) {
        return;
    }
    glPushMatrix();
    gl::translate(getWindowCenter());
    float w= getWindowWidth();
    float a= getWindowHeight()*0.25f;    //wave amplitude
    PolyLine<Vec2f>	line;
    for(uint32_t i= 0; i<mBufferSize; i++) {
        float x= (i/(float)(mBufferSize-1))*w-(w*0.5f);
        float y= mBufferLeft->mData[i]*a;
        line.push_back(Vec2f(x, y));
        if(fill) {
            line.push_back(Vec2f(x, 0.0f-y));
        }
    }
    gl::draw(line);
    glPopMatrix();
}
Beispiel #12
0
void HelixObject::BuildShape(TimeValue t, PolyShape& ashape) {
	// Set the object's interpolation parameters
	ReadyInterpParams(t);
	// Set the general interval to the one we just got
	ivalid = interpValid;
	ashape.NewShape();
	// Start a PolyLine for our helix...
	PolyLine *line = ashape.NewLine();
	// Compute some helpful stuff...
	int points = (int)(turns * (float)POINTS_PER_TURN);
	if(points == 0)
		points = 1;
	float fPoints = (float)points;
	numberOfPieces = 0;
	for(int i = 0; i <= points; ++i) {
		float pct = (float)i / fPoints;
		float r = radius1 + deltaRadius * pct;
		float hpct = pct;
		if(bias > 0.0f)
			hpct = 1.0f - (float)pow(1.0f - pct, power );
		else
		if(bias < 0.0f)
			hpct = (float)pow(pct, power);
			
		float z = height * hpct;
		float angle = totalRadians * pct;
		float x = r * (float)cos(angle);
		float y = r * (float)sin(angle);
		DWORD flags = POLYPT_SMOOTH;
		if((i % 10) == 0 || i == points) {
			flags |= POLYPT_KNOT;	// Let it know the piece boundary
			if(i > 0)
				numberOfPieces++;
			}
		line->Append(PolyPt(Point3(x,y,z), flags));
		}
	perPiece = 1.0f / (float)numberOfPieces;
	ashape.UpdateSels();	// Make sure it readies the selection set info
	ashape.InvalidateGeomCache(FALSE);
	lengthOfCurve = ashape.lines[0].CurveLength();
	}
void TouchAudioTestApp::drawWaveForm()
{
	if( ! mPcmBuffer ) {
		return;
	}
	
	uint32_t bufferSamples = mPcmBuffer->getSampleCount();
	audio::Buffer32fRef leftBuffer = mPcmBuffer->getChannelData( audio::CHANNEL_FRONT_LEFT );
	//audio::Buffer32fRef rightBuffer = mPcmBuffer->getChannelData( audio::CHANNEL_FRONT_RIGHT );
	
	float center = getWindowWidth() / 2;
	float displaySize = getWindowHeight();
	uint32_t endIdx = bufferSamples;
	
	//only draw the last 1024 samples or less
	int32_t startIdx = ( endIdx - 1024 );
	startIdx = math<int32_t>::clamp( startIdx, 0, endIdx );
	
	float scale = displaySize / (float)( endIdx - startIdx );
	//float scale = displaySize / (float)( endIdx );
	
	PolyLine<vec2>	line;
	
	gl::color( Color( 1.0f, 0.5f, 0.25f ) );
	for( uint32_t i = startIdx, c = 0; i < endIdx; i++, c++ ) {
		float y = ( ( leftBuffer->mData[i] - 1 ) * - center );
		line.push_back( vec2( y, ( c * scale ) ) );
	}
	gl::draw( line );
	
	/*glColor3f( 1.0f, 0.96f, 0.0f );
	glBegin( GL_LINE_STRIP );
	for( int i = 0; i < endIdx; i++ ) {
		float y = ( ( rightBuffer->mData[i] - 1 ) * - 100 );
		glVertex2f( ( i * scale ) , y );
	}
	glEnd();*/
}
Beispiel #14
0
void ExtrudeMod::BuildPatchFromShape(TimeValue t,ModContext &mc, ObjectState * os, PatchMesh &pmesh) {
	ShapeObject *shape = (ShapeObject *)os->obj;

	float amount;
	int levels,capStart,capEnd,capType;

	pblock->GetValue(PB_AMOUNT,t,amount,FOREVER);
	pblock->GetValue(PB_SEGS,t,levels,FOREVER);
	if (levels<1) levels = 1;
	pblock->GetValue(PB_CAPSTART,t,capStart,FOREVER);
	pblock->GetValue(PB_CAPEND,t,capEnd,FOREVER);
	pblock->GetValue(PB_CAPTYPE,t,capType,FOREVER);

	BOOL texturing;
	pblock->GetValue(PB_MAPPING, TimeValue(0), texturing, FOREVER);
	BOOL genMatIDs;
	pblock->GetValue(PB_GEN_MATIDS, TimeValue(0), genMatIDs, FOREVER);
	BOOL useShapeIDs;
	pblock->GetValue(PB_USE_SHAPEIDS, TimeValue(0), useShapeIDs, FOREVER);
	BOOL smooth;
	pblock->GetValue(PB_SMOOTH, TimeValue(0), smooth, FOREVER);

	LimitValue(amount, -1000000.0f, 1000000.0f);

	// Get the basic dimension stuff
	float zSize = (float)fabs(amount);
	float baseZ = 0.0f;
	if(amount < 0.0f)
		baseZ = amount;

	// If the shape can convert itself to a BezierShape, have it do so!
	BezierShape bShape;
	if(shape->CanMakeBezier())
		shape->MakeBezier(t, bShape);
	else {
		PolyShape pShape;
		shape->MakePolyShape(t, pShape);
		bShape = pShape;	// UGH -- Convert it from a PolyShape -- not good!
		}
	
//DebugPrint(_T("Extrude organizing shape\n"));
	ShapeHierarchy hier;
	bShape.OrganizeCurves(t, &hier);
	// Need to flip the reversed polys...
	bShape.Reverse(hier.reverse);
	// ...and tell the hierarchy they're no longer reversed!
	hier.reverse.ClearAll();

	// Our shapes are now organized for patch-making -- Let's do the sides!
	int polys = bShape.splineCount;
	int poly, knot;
	int levelVerts = 0, levelVecs = 0, levelPatches = 0, nverts = 0, nvecs = 0, npatches = 0;
	int TVlevels = levels + 1, levelTVerts = 0, ntverts = 0, ntpatches = 0;
	BOOL anyClosed = FALSE;
	for(poly = 0; poly < polys; ++poly) {
		Spline3D *spline = bShape.splines[poly];
		if(!spline->KnotCount())
			continue;
		if(spline->Closed())
			anyClosed = TRUE;
		levelVerts += spline->KnotCount();
		levelTVerts += (spline->Segments() + 1);
		levelVecs += (spline->Segments() * 2);
		levelPatches += spline->Segments();
		}
	nverts = levelVerts * (levels + 1);
	npatches = levelPatches * levels;
	nvecs = (levelVecs * (levels + 1)) + levels * levelVerts * 2 + npatches * 4;
	if(texturing) {
		ntverts = levelTVerts * TVlevels;
		ntpatches = npatches;
		}

	pmesh.setNumVerts(nverts);
	pmesh.setNumVecs(nvecs);
	pmesh.setNumPatches(npatches);
	pmesh.setNumTVerts(ntverts);
	pmesh.setNumTVPatches(ntpatches);

	// Create the vertices!
	int vert = 0;
	int level;
	Point3 offset1, offset2;
	for(poly = 0; poly < polys; ++poly) {
		Spline3D *spline = bShape.splines[poly];
		if(!spline->KnotCount())
			continue;
		int knots = spline->KnotCount();
		for(level = 0; level <= levels; ++level) {
			Point3 offset = Point3(0.0f, 0.0f, baseZ + (float)level / (float)levels * zSize);
			if(level == 0)
				offset1 = offset;
			else
			if(level == levels)
				offset2 = offset;
			for(knot = 0; knot < knots; ++knot) {
				Point3 p = spline->GetKnotPoint(knot);
				pmesh.setVert(vert++, p + offset);
				}
			}
		}
	assert(vert == nverts);

    BOOL usePhysUVs = GetUsePhysicalScaleUVs();
	// Maybe create the texture vertices
	if(texturing) {
		int tvert = 0;
		int level;
		for(poly = 0; poly < polys; ++poly) {
			Spline3D *spline = bShape.splines[poly];
			if(!spline->KnotCount())
				continue;
			// Make it a polyline
			PolyLine pline;
			spline->MakePolyLine(pline, 10);
			int knots = spline->KnotCount();
			for(level = 0; level < TVlevels; ++level) {
				float tV = (float)level / (float)(TVlevels - 1);
                float vScale = usePhysUVs ? amount : 1.0f;
				int lverts = pline.numPts;
				int tp = 0;
				int texPts = spline->Segments() + 1;
				float cumLen = 0.0f;
				float totLen = pline.CurveLength();
                float uScale = usePhysUVs ? totLen : 1.0f;
				Point3 prevPt = pline.pts[0].p;
				int plix = 0;
				while(tp < texPts) {
					Point3 &pt = pline[plix].p;
					cumLen += Length(pt - prevPt);
					prevPt = pt;
					if(pline[plix].flags & POLYPT_KNOT) {
						float tU;
						if(tp == (texPts - 1))
							tU = 1.0f;
						else
							tU = cumLen / totLen;
						pmesh.setTVert(tvert++, UVVert(uScale*tU, vScale*tV, 0.0f));
						tp++;
						}
					plix = (plix + 1) % pline.numPts;
					}
				}
			}
		assert(tvert == ntverts);
		}

	// Create the vectors!
	int seg;
	int vec = 0;
	for(poly = 0; poly < polys; ++poly) {
		Spline3D *spline = bShape.splines[poly];
		if(!spline->KnotCount())
			continue;
		int segs = spline->Segments();
		int knots = spline->KnotCount();
		// First, the vectors on each level
		for(level = 0; level <= levels; ++level) {
			Point3 offset = Point3(0.0f, 0.0f, baseZ + (float)level / (float)levels * zSize);
			for(seg = 0; seg < segs; ++seg) {
				int seg2 = (seg + 1) % knots;
				if(spline->GetLineType(seg) == LTYPE_CURVE) {
					Point3 p = spline->GetOutVec(seg);
					pmesh.setVec(vec++, p + offset);
					p = spline->GetInVec(seg2);
					pmesh.setVec(vec++, p + offset);
					}
				else {
					Point3 p = spline->InterpBezier3D(seg, 0.333333f);
					pmesh.setVec(vec++, p + offset);
					p = spline->InterpBezier3D(seg, 0.666666f);
					pmesh.setVec(vec++, p + offset);
					}
				}
			}
		// Now, the vectors between the levels
		int baseVec = vec;
		for(level = 0; level < levels; ++level) {
			Point3 offsetA = Point3(0.0f, 0.0f, baseZ + (float)level / (float)levels * zSize);
			Point3 offsetB = Point3(0.0f, 0.0f, baseZ + (float)(level + 1) / (float)levels * zSize);
			Point3 offset1 = offsetA + (offsetB - offsetA) * 0.333333333f;
			Point3 offset2 = offsetA + (offsetB - offsetA) * 0.666666666f;
			for(knot = 0; knot < knots; ++knot) {
				Point3 p = spline->GetKnotPoint(knot);
				pmesh.setVec(vec++, p + offset1);
				pmesh.setVec(vec++, p + offset2);
				}
			}
		}

	// Create the patches!
	int np = 0;
	int baseVert = 0;
	int baseVec = 0;
	for(poly = 0; poly < polys; ++poly) {
		Spline3D *spline = bShape.splines[poly];
		if(!spline->KnotCount())
			continue;
		int knots = spline->KnotCount();
		int segs = spline->Segments();
		int baseVec1 = baseVec;	// Base vector index for this level
		int baseVec2 = baseVec + segs * 2 * (levels + 1);	// Base vector index for between levels
		for(level = 0; level < levels; ++level) {
			int sm = 0;
			BOOL firstSmooth = (spline->GetLineType(0) == LTYPE_CURVE && spline->GetLineType(segs-1) == LTYPE_CURVE && (spline->GetKnotType(0) == KTYPE_AUTO || spline->GetKnotType(0) == KTYPE_BEZIER)) ? TRUE : FALSE;
			for(seg = 0; seg < segs; ++seg, vec += 4) {
				int prevseg = (seg + segs - 1) % segs;
				int seg2 = (seg + 1) % knots;
				int a,b,c,d,ab,ba,bc,cb,cd,dc,da,ad;
				MtlID mtl = useShapeIDs ? spline->GetMatID(seg) : 2;
				a = baseVert + seg;
				b = baseVert + seg2;
				c = b + knots;
				d = a + knots;
				ab = baseVec1 + seg * 2;
				ba = ab + 1;
				bc = baseVec2 + seg2 * 2;
				cb = bc + 1;
				cd = ba + (segs * 2);
				dc = ab + (segs * 2);
				da = baseVec2 + seg * 2 + 1;
				ad = da - 1;
//DebugPrint(_T("Making patch %d: %d (%d %d) %d (%d %d) %d (%d %d) %d (%d %d)\n"),np, a, ab, ba, b, bc, cb, c, cd, dc, d, da, ad);
				// If the vertex is not smooth, go to the next group!
				if(seg > 0 && !(spline->GetLineType(prevseg) == LTYPE_CURVE && spline->GetLineType(seg) == LTYPE_CURVE && (spline->GetKnotType(seg) == KTYPE_AUTO || spline->GetKnotType(seg) == KTYPE_BEZIER))) {
					sm++;
					if(sm > 2)
						sm = 1;
					}
				DWORD smoothGroup = 1 << sm;
				if(seg == segs - 1 && firstSmooth) {
					smoothGroup |= 1;
					}
				pmesh.MakeQuadPatch(np, a, ab, ba, b, bc, cb, c, cd, dc, d, da, ad, vec, vec+1, vec+2, vec+3, smooth ? smoothGroup : 0);
				pmesh.setPatchMtlIndex(np++, genMatIDs ? mtl : 0);
				}
			baseVert += knots;
			baseVec1 += (segs * 2);
			baseVec2 += (knots * 2);
			}
		baseVert += knots;
		baseVec += (segs * 2 * (levels + 1) + knots * 2 * levels);
		}
	assert(vec == nvecs);
	assert(np == npatches);

 	// Maybe create the texture patches!
	if(texturing) {
		int ntp = 0;
		int baseTVert = 0;
		for(poly = 0; poly < polys; ++poly) {
			Spline3D *spline = bShape.splines[poly];
			if(!spline->KnotCount())
				continue;
			int pknots = spline->Segments() + 1;
			int pverts = pknots * TVlevels;
			int segs = spline->Segments();
			for(level = 0; level < levels; ++level) {
				for(seg = 0; seg < segs; ++seg) {
					int prevseg = (seg + segs - 1) % segs;
					int seg2 = seg + 1;
					int a,b,c,d;
					a = baseTVert + seg;
					b = baseTVert + seg2;
					c = b + pknots;
					d = a + pknots;
					TVPatch &tp = pmesh.getTVPatch(ntp++);
					tp.setTVerts(a, b, c, d);
					
					}
				baseTVert += pknots;
				}
			baseTVert += pknots;
			}
		assert(ntp == ntpatches);
		}

	// If capping, do it!
	if(anyClosed && (capStart || capEnd)) {
		PatchCapInfo capInfo;
		bShape.MakeCap(t, capInfo);

		// Build information for capping
		PatchCapper capper(bShape);
		if(capStart) {
			vert = 0;
			int baseVec = 0;
			for(poly = 0; poly < polys; ++poly) {
				Spline3D *spline = bShape.splines[poly];
				if(!spline->KnotCount())
					continue;
				PatchCapPoly &capline = capper[poly];
				int lverts = spline->KnotCount();
				for(int v = 0; v < lverts; ++v)
					capline.SetVert(v, vert++);			// Gives this vert's location in the mesh!
				vert += lverts * levels;
				vec = baseVec;
				int lvecs = spline->Segments() * 2;
				for(int v = 0; v < lvecs; ++v)
					capline.SetVec(v, vec++);			// Gives this vec's location in the mesh!
				baseVec += lvecs * (levels + 1) + spline->KnotCount() * levels * 2;
				}
			// Create a work matrix for capping
			Matrix3 mat = TransMatrix(offset1);
			int oldPatches = pmesh.numPatches;
			capper.CapPatchMesh(pmesh, capInfo, TRUE, 16, &mat, genMatIDs ? -1 : 0);
			// If texturing, create the texture patches and vertices
			if(texturing)
				MakePatchCapTexture(pmesh, Inverse(mat), oldPatches, pmesh.numPatches, usePhysUVs);
			}
		if(capEnd) {
			int baseVert = 0;
			int baseVec = 0;
			for(poly = 0; poly < polys; ++poly) {
				Spline3D *spline = bShape.splines[poly];
				if(!spline->KnotCount())
					continue;
				PatchCapPoly &capline = capper[poly];
				int lverts = spline->KnotCount();
				int vert = baseVert + lverts * levels;
				for(int v = 0; v < lverts; ++v)
					capline.SetVert(v, vert++);			// Gives this vert's location in the mesh!
				baseVert += lverts * (levels + 1);
				int lvecs = spline->Segments()*2;
				int vec = baseVec + lvecs * levels;
				for(int v = 0; v < lvecs; ++v)
					capline.SetVec(v, vec++);			// Gives this vec's location in the mesh!
				baseVec += lvecs * (levels + 1) + spline->KnotCount() * levels * 2;
				}
			// Create a work matrix for grid capping
			Matrix3 mat = TransMatrix(offset2);
			int oldPatches = pmesh.numPatches;
			capper.CapPatchMesh(pmesh, capInfo, FALSE, 16, &mat, genMatIDs ? -1 : 0);
			// If texturing, create the texture patches and vertices
			if(texturing)
				MakePatchCapTexture(pmesh, Inverse(mat), oldPatches, pmesh.numPatches, usePhysUVs);
			}
		}

	//watje new mapping
	if(texturing)
		{
		if (ver < 4)
			{
			for (int i = 0; i < pmesh.numPatches; i++)
				pmesh.patches[i].flags |= PATCH_LINEARMAPPING;
			}
		}


	// Ready the patch representation!
	if( !pmesh.buildLinkages() )
   {
      assert(0);
   }
	pmesh.computeInteriors();
	}
Beispiel #15
0
void Puppeteer::draw()
{
    // ----------------------------debug

    if (Constants::Debug::DRAW_PUPPETEER_BOUNDS) {
        Vec3f origin = Vec3f::zero();
        PolyLine<Vec3f> boundsL;
        boundsL.push_back(origin - axisVert * armLenL);
        boundsL.push_back(origin - axisVert * armLenL + axisHoriz * armLenL);
        boundsL.push_back(origin + axisVert * armLenL + axisHoriz * armLenL);
        boundsL.push_back(origin + axisVert * armLenL);
        boundsL.push_back(origin - axisVert * armLenL);
        boundsL.push_back(origin - axisVert * armLenL + normal * armLenL); //
        boundsL.push_back(origin - axisVert * armLenL + normal * armLenL + axisHoriz * armLenL);
        boundsL.push_back(origin + axisVert * armLenL + normal * armLenL + axisHoriz * armLenL);
        boundsL.push_back(origin + axisVert * armLenL + normal * armLenL);
        boundsL.push_back(origin - axisVert * armLenL + normal * armLenL);

        PolyLine<Vec3f> boundsR;
        boundsR.push_back(origin - axisVert * armLenR);
        boundsR.push_back(origin - axisVert * armLenR - axisHoriz * armLenR);
        boundsR.push_back(origin + axisVert * armLenR - axisHoriz * armLenR);
        boundsR.push_back(origin + axisVert * armLenR);
        boundsR.push_back(origin - axisVert * armLenR);
        boundsR.push_back(origin - axisVert * armLenR + normal * armLenR); //
        boundsR.push_back(origin - axisVert * armLenR + normal * armLenR - axisHoriz * armLenR);
        boundsR.push_back(origin + axisVert * armLenR + normal * armLenR - axisHoriz * armLenR);
        boundsR.push_back(origin + axisVert * armLenR + normal * armLenR);
        boundsR.push_back(origin - axisVert * armLenR + normal * armLenR);

        gl::pushMatrices();

        MayaCamUI* mayaCam = Constants::mayaCam();
        gl::setMatrices(mayaCam->getCamera());

        float scale = 1.0f;
        // original bounding boxes
        gl::color(Color(0.5f, 0.5f, 0.5f));
        gl::pushModelView();
        gl::translate(shoulderL);
        gl::draw(boundsL);
        gl::popModelView();

        gl::pushModelView();
        gl::translate(shoulderR);
        gl::draw(boundsR);
        gl::popModelView();

        // normalized bound boxes
        gl::color(Color(0, 0, 1));
        gl::pushModelView();
        gl::translate(-.5f, 0, 0);
        gl::scale(scale, scale, scale);
        gl::rotate( Quatf(normalizationMatrix) );
        gl::draw(boundsL);
        gl::popModelView();

        gl::pushModelView();
        gl::translate(-.5f, 0, 0);
        gl::scale(scale, scale, scale);
        gl::drawCube(handL, Vec3f(0.1f, 0.1f, 0.1f));
        gl::popModelView();

        gl::color(Color(0, 1, 0));
        gl::pushModelView();
        gl::translate(.5f, 0, 0);
        gl::scale(scale, scale, scale);
        gl::rotate( Quatf(normalizationMatrix) );
        gl::draw(boundsR);
        gl::popModelView();

        gl::pushModelView();
        gl::translate(.5f, 0, 0);
        gl::scale(scale, scale, scale);
        gl::drawCube(handR, Vec3f(0.1f, 0.1f, 0.1f));
        gl::popModelView();

        gl::popMatrices();

        gl::color( Color(1, 1, 1));
    }

    arduino->draw();
}
Beispiel #16
0
int main(int argc, char *argv[])
{
	Figure f;

	// get some coordinates ready to use in a lot of objects
	
	Coordinate *a = new Coordinate (500,500);
	Coordinate *b = new Coordinate (1500,1500);

	// draw a polyline

	PolyLine *polyline = new PolyLine(a, b);
	polyline->push_back(new Coordinate(2000,1500));
	polyline->setLineStyle(Attributes::Dotted);
	
	// give the polyline arrows
	
	Arrow arr;
	arr.setType(Arrow::ClosedPointed);
	arr.setStyle(Arrow::Filled);

	polyline->setBackwardArrowBool(1);
	polyline->setBackwardArrow(arr);
	
	polyline->setForwardArrowBool(1);
	polyline->setForwardArrow(arr);
	
	// polyline is ready, keep it in the fig
	
	f.push_back(polyline);
	
	// an example box using the same coordinates

	Box *box = new Box(a, b);
	box->setThickness(2);
	f.push_back(box);
	
	// an ellipse in that box

	RadiiEllipse *re = new RadiiEllipse(new Coordinate(1000, 1000), new Coordinate(500, 200));
	f.push_back(re);
	
	// another ellipse in that box

	DiameterEllipse *de = new DiameterEllipse(new Coordinate(500, 800), new Coordinate(1500, 1200));
	f.push_back(de);
	
	// a circle defined by a radius, in the box

	RadiusCircle *rc = new RadiusCircle(new Coordinate(1000, 1000), 500);
	f.push_back(rc);
	
	// a circle defined by two points defining its radius

	DiameterCircle *dc = new DiameterCircle(a, b);
	f.push_back(dc);
	
	// some text

	Text* text = new Text(new Coordinate(1900, 900), "fig++");
	text->setFontSize(50);
	f.push_back(text);

	// an arc defined by its three defining points
	// first point comes first

	Arc* arc = new Arc(new Coordinate(1000, 1000), new Coordinate(2000, 1000), new Coordinate(2000, 2000));
	f.push_back(arc);
	
	// this is what's useful: putting something on an arbitrary place

	for (float x = 0; x <= 314; x=x+19.625) {
		PolyLine *l = 
			new PolyLine( 
				new Coordinate(
					(int)(1500.0+500.0*cos(x/100)),
					(int)(1500.0+500.0*sin(x/100))
				),
				new Coordinate(
					(int)(1500.0+1000.0*cos(x/100)),
					(int)(1500.0+1000.0*sin(x/100))
				)
			);
		l->setForwardArrowBool(1);
		arr.setType(Arrow::ClosedIntended);
		l->setForwardArrow(arr);
		f.push_back(l);
	}
	
	// a vector of coordinates

	std::vector<Coordinate *> vc;

	vc.push_back( new Coordinate (2500, 500) );
	vc.push_back( new Coordinate (3000, 500) );
	vc.push_back( new Coordinate (3000, 1000) );
	vc.push_back( new Coordinate (3500, 1000) );
	vc.push_back( new Coordinate (3500, 1500) );
	vc.push_back( new Coordinate (3000, 1500) );
	vc.push_back( new Coordinate (3000, 2000) );
	vc.push_back( new Coordinate (2500, 2000) );
	vc.push_back( new Coordinate (2500, 1500) );
	vc.push_back( new Coordinate (2000, 1500) );
	vc.push_back( new Coordinate (2000, 1000) );
	vc.push_back( new Coordinate (2500, 1000) );
	
	// the vector as a polyline

	Polygon *pl = new Polygon ();
	for (std::vector<Coordinate *>::iterator i = vc.begin(); i != vc.end(); i++)
		pl->push_back(*i);
	f.push_back(pl);
	
	// two possible splines defined by the vector

	Spline *spline1 = new Spline();
	Spline *spline2 = new Spline();
	for (std::vector<Coordinate *>::iterator i = vc.begin(); i != vc.end(); i++) {
		spline1->push_back( new SplineCoordinate(*i, -1) ); // interpolated
		spline2->push_back( new SplineCoordinate(*i, 1) ); //approximated
	}
	spline1->setSubType(Spline::Closed);
	f.push_back(spline1);
	spline2->setSubType(Spline::Closed);
	f.push_back(spline2);
	
	// print the file to the standard out

	std::cout << f;

	return EXIT_SUCCESS;
}
// Render
void KinectApp::draw()
{

	// Clear window
	gl::setViewport( getWindowBounds() );
	gl::clear( Colorf( 0.1f, 0.1f, 0.1f ) );

	// We're capturing
	if ( mKinect->isCapturing() ) {

		// Set up camera for 3D
		gl::setMatrices( mCamera );

		// Move skeletons down below the rest of the interface
		gl::pushMatrices();
		gl::translate( 0.0f, -0.62f, 0.0f );

		// Iterate through skeletons
		uint32_t i = 0;
		for ( vector<Skeleton>::const_iterator skeletonIt = mSkeletons.cbegin(); skeletonIt != mSkeletons.cend(); ++skeletonIt, i++ ) {

			// Skeleton is valid when all joints are present
			if ( skeletonIt->size() == JointName::NUI_SKELETON_POSITION_COUNT ) {

				// Set color
				gl::color( mKinect->getUserColor( i ) );

				// Draw joints
				for ( Skeleton::const_iterator jointIt = skeletonIt->cbegin(); jointIt != skeletonIt->cend(); ++jointIt ) {
					gl::drawSphere( jointIt->second * Vec3f( -1.0f, 1.0f, 1.0f ), 0.025f, 16 );
				}

				// Draw body
				for ( vector<vector<JointName> >::const_iterator segmentIt = mSegments.cbegin(); segmentIt != mSegments.cend(); ++segmentIt ) {
					drawSegment( * skeletonIt, * segmentIt );
				}

			}

		}

		// Switch to 2D
		gl::popMatrices();
		gl::setMatricesWindow( getWindowSize(), true );

		// Draw depth and video textures
		gl::color( Colorf::white() );
		if ( mDepthSurface ) {
			Area srcArea( 0, 0, mDepthSurface.getWidth(), mDepthSurface.getHeight() );
			Rectf destRect( 265.0f, 15.0f, 505.0f, 195.0f );
			gl::draw( gl::Texture( mDepthSurface ), srcArea, destRect );
		}
		if ( mVideoSurface ) {
			Area srcArea( 0, 0, mVideoSurface.getWidth(), mVideoSurface.getHeight() );
			Rectf destRect( 508.0f, 15.0f, 748.0f, 195.0f );
			gl::draw( gl::Texture( mVideoSurface ), srcArea, destRect);
		}

	}

	// Check audio data
	if ( mData != 0 ) {

		// Get dimensions
		int32_t dataSize = mInput->getDataSize();
		float scale = 240.0f / (float)dataSize;
		float height = 180.0f;
		Vec2f position( 751.0f, 15.0f );

		// Draw background
		gl::color( ColorAf::black() );
		Rectf background( position.x, position.y, position.x + 240.0f, position.y + 180.0f );
		gl::drawSolidRect( background );

		// Draw audio input
		gl::color( ColorAf::white() );
		PolyLine<Vec2f> mLine;
		for ( int32_t i = 0; i < dataSize; i++ ) {
			mLine.push_back( position + Vec2f( i * scale, math<float>::clamp( mData[ i ], -1.0f, 1.0f ) * height * 0.5f + height * 0.5f ) );
		}
		if ( mLine.size() > 0 ) {
			gl::draw( mLine );
		}

	}

	// Draw the interface
	params::InterfaceGl::draw();

}
void mitk::PlanarFigureVtkMapper3D::GenerateDataForRenderer(BaseRenderer* renderer)
{
  typedef PlanarFigure::PolyLineType PolyLine;

  DataNode* node = this->GetDataNode();

  if (node == NULL)
    return;

  PlanarFigure* planarFigure = dynamic_cast<PlanarFigure*>(node->GetData());

  if (planarFigure == NULL || !planarFigure->IsPlaced())
    return;

  LocalStorage* localStorage = m_LocalStorageHandler.GetLocalStorage(renderer);
  unsigned long mTime = planarFigure->GetMTime();

  if (mTime > localStorage->m_LastMTime)
  {
    localStorage->m_LastMTime = mTime;

    const PlaneGeometry* planeGeometry = dynamic_cast<const PlaneGeometry*>(planarFigure->GetPlaneGeometry());
    const AbstractTransformGeometry* abstractTransformGeometry = dynamic_cast<const AbstractTransformGeometry*>(planarFigure->GetPlaneGeometry());

    if (planeGeometry == NULL && abstractTransformGeometry == NULL)
      return;

    size_t numPolyLines = planarFigure->GetPolyLinesSize();

    if (numPolyLines == 0)
      return;

    vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
    vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New();
    vtkIdType baseIndex = 0;

    for (size_t i = 0; i < numPolyLines; ++i)
    {
      PolyLine polyLine = planarFigure->GetPolyLine(i);
      vtkIdType numPoints = polyLine.size();

      if (numPoints < 2)
        continue;

      PolyLine::const_iterator polyLineEnd = polyLine.end();

      for (PolyLine::const_iterator polyLineIt = polyLine.begin(); polyLineIt != polyLineEnd; ++polyLineIt)
      {
        Point3D point;
        planeGeometry->Map(*polyLineIt, point);
        points->InsertNextPoint(point.GetDataPointer());
      }

      vtkSmartPointer<vtkPolyLine> line = vtkSmartPointer<vtkPolyLine>::New();

      vtkIdList* pointIds = line->GetPointIds();

      if (planarFigure->IsClosed() && numPoints > 2)
      {
        pointIds->SetNumberOfIds(numPoints + 1);
        pointIds->SetId(numPoints, baseIndex);
      }
      else
      {
        pointIds->SetNumberOfIds(numPoints);
      }

      for (vtkIdType j = 0; j < numPoints; ++j)
        pointIds->SetId(j, baseIndex + j);

      cells->InsertNextCell(line);

      baseIndex += points->GetNumberOfPoints();
    }

    vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New();
    polyData->SetPoints(points);
    polyData->SetLines(cells);

    vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
    mapper->SetInputData(polyData);

    localStorage->m_Actor->SetMapper(mapper);
  }

  this->ApplyColorAndOpacityProperties(renderer, localStorage->m_Actor);
  this->ApplyPlanarFigureProperties(renderer, localStorage->m_Actor);
}
void mitk::ExtrudePlanarFigureFilter::GenerateData()
{
  typedef PlanarFigure::PolyLineType PolyLine;
  typedef PolyLine::const_iterator PolyLineConstIter;

  if (m_Length <= 0)
    mitkThrow() << "Length is not positive!";

  if (m_NumberOfSegments == 0)
    mitkThrow() << "Number of segments is zero!";

  if (m_BendAngle != 0 && m_BendDirection[0] == 0 && m_BendDirection[1] == 0)
    mitkThrow() << "Bend direction is zero-length vector!";

  PlanarFigure* input = dynamic_cast<PlanarFigure*>(this->GetPrimaryInput());

  if (input == NULL)
    mitkThrow() << "Primary input is not a planar figure!";

  size_t numPolyLines = input->GetPolyLinesSize();

  if (numPolyLines == 0)
    mitkThrow() << "Primary input does not contain any poly lines!";

  const PlaneGeometry* planeGeometry = dynamic_cast<const PlaneGeometry*>(input->GetPlaneGeometry());

  if (planeGeometry == NULL)
    mitkThrow() << "Could not get plane geometry from primary input!";

  Vector3D planeNormal = planeGeometry->GetNormal();
  planeNormal.Normalize();

  Point2D centerPoint2d = GetCenterPoint(input);

  Point3D centerPoint3d;
  planeGeometry->Map(centerPoint2d, centerPoint3d);

  Vector3D bendDirection3d = m_BendAngle != 0
    ? ::GetBendDirection(planeGeometry, centerPoint2d, m_BendDirection)
    : Vector3D();

  ScalarType radius = m_Length * (360 / m_BendAngle) / (2 * vnl_math::pi);
  Vector3D scaledBendDirection3d = bendDirection3d * radius;

  Vector3D bendAxis = itk::CrossProduct(planeNormal, bendDirection3d);
  bendAxis.Normalize();

  vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
  vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New();
  vtkIdType baseIndex = 0;

  for (size_t i = 0; i < numPolyLines; ++i)
  {
    PolyLine polyLine = input->GetPolyLine(i);
    size_t numPoints = polyLine.size();

    if (numPoints < 2)
      mitkThrow() << "Poly line " << i << " of primary input consists of less than two points!";

    std::vector<mitk::Point3D> crossSection;

    PolyLineConstIter polyLineEnd = polyLine.end();

    for (PolyLineConstIter polyLineIter = polyLine.begin(); polyLineIter != polyLineEnd; ++polyLineIter)
    {
      Point3D point;
      planeGeometry->Map(*polyLineIter, point);
      crossSection.push_back(point);
    }

    ScalarType segmentLength = m_Length / m_NumberOfSegments;
    Vector3D translation = planeNormal * segmentLength;

    bool bend = std::abs(m_BendAngle) > mitk::eps;
    bool twist = std::abs(m_TwistAngle) > mitk::eps;

    ScalarType twistAngle = twist
      ? m_TwistAngle / m_NumberOfSegments * vnl_math::pi / 180
      : 0;

    ScalarType bendAngle = bend
      ? m_BendAngle / m_NumberOfSegments * vnl_math::pi / 180
      : 0;

    if (m_FlipDirection)
    {
      translation *= -1;
      bendAngle *= -1;
    }

    for (size_t k = 0; k < numPoints; ++k)
      points->InsertNextPoint(crossSection[k].GetDataPointer());

    for (size_t j = 1; j <= m_NumberOfSegments; ++j)
    {
      mitk::AffineTransform3D::Pointer transform = mitk::AffineTransform3D::New();

      if (bend || twist)
        transform->Translate(centerPoint3d.GetVectorFromOrigin(), true);

      if (bend)
      {
        transform->Translate(scaledBendDirection3d, true);
        transform->Rotate3D(bendAxis, bendAngle * j, true);
        transform->Translate(-scaledBendDirection3d, true);
      }
      else
      {
        transform->Translate(translation * j, true);
      }

      if (twist)
        transform->Rotate3D(planeNormal, twistAngle * j, true);

      if (bend || twist)
        transform->Translate(-centerPoint3d.GetVectorFromOrigin(), true);

      for (size_t k = 0; k < numPoints; ++k)
      {
        mitk::Point3D transformedPoint = transform->TransformPoint(crossSection[k]);
        points->InsertNextPoint(transformedPoint.GetDataPointer());
      }
    }

    for (size_t j = 0; j < m_NumberOfSegments; ++j)
    {
      for (size_t k = 1; k < numPoints; ++k)
      {
        vtkIdType cell[3];
        cell[0] = baseIndex + j * numPoints + (k - 1);
        cell[1] = baseIndex + (j + 1) * numPoints + (k - 1);
        cell[2] = baseIndex + j * numPoints + k;

        cells->InsertNextCell(3, cell);

        cell[0] = cell[1];
        cell[1] = baseIndex + (j + 1) * numPoints + k;

        cells->InsertNextCell(3, cell);
      }

      if (input->IsClosed() && numPoints > 2)
      {
        vtkIdType cell[3];
        cell[0] = baseIndex + j * numPoints + (numPoints - 1);
        cell[1] = baseIndex + (j + 1) * numPoints + (numPoints - 1);
        cell[2] = baseIndex + j * numPoints;

        cells->InsertNextCell(3, cell);

        cell[0] = cell[1];
        cell[1] = baseIndex + (j + 1) * numPoints;

        cells->InsertNextCell(3, cell);
      }
    }

    baseIndex += points->GetNumberOfPoints();
  }

  vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New();
  polyData->SetPoints(points);
  polyData->SetPolys(cells);

  vtkSmartPointer<vtkPolyDataNormals> polyDataNormals = vtkSmartPointer<vtkPolyDataNormals>::New();
  polyDataNormals->SetFlipNormals(m_FlipNormals);
  polyDataNormals->SetInputData(polyData);
  polyDataNormals->SplittingOff();

  polyDataNormals->Update();

  Surface* output = static_cast<Surface*>(this->GetPrimaryOutput());
  output->SetVtkPolyData(polyDataNormals->GetOutput());
}