Hi there, I would need some help with my code...its in python, and the thing I have to do is to make points of the matrix of the object be displayed in a way to make the first camera position as a start of the coordinate system! to clarify a bit, I have camera coordinates of the viewpoints, and than would just display the object matrix by referring to the world coordinates...now I have to make it referring to the first camera position?btw, no need to say that its total amateur of python involved!so any suggestions?
have a look...

matrix = extCam.GetViewTransformObject().GetMatrix()
		matrix.Invert()	
		
		pointsFromThisView = list()
		width = disparity.rows
		for i in range(disparity.rows):
			for j in range(disparity.rows):
				if disparity[i,j] >= 0:
					p = [_3dImage[i,j][0]*-1,_3dImage[i,j][1],_3dImage[i,j][2], 1] #camera coordinates
					pp = matrix.MultiplyPoint(p) #world coordinates I first used
					pointsFromThisView.append(p)					

		print "Points in the current view:", len(pointsFromThisView)
		mergePoints.extend(pointsFromThisView)

print "Points after merging views:", len(mergePoints)



###############
coneSource = vtk.vtkConeSource()
coneSource.SetResolution(6)
	
mypoints = vtk.vtkPoints()
poly = vtk.vtkPolyData()
conn = vtk.vtkCellArray()

for p in mergePoints:
	mypoints.InsertNextPoint(p[0],p[1],p[2])
	a = conn.InsertNextCell(1)	
			
poly.SetPoints(mypoints)
poly.SetVerts(conn)

I do not understand the a variable which is overwritten and never used. Why don't you just substract the new origin from all points?

a variable is used (it is mentioned before this scrap of the code, so it makes sense),but anyway, how do u mean just substract new origin?

and small correction:

pointsFromThisView.append(pp)

I suggested this:

from pprint import pprint
import random
number_of_points = 40
camera_coords = [(random.randint(-1000,1000),random.randint(-1000,1000),random.randint(-1000,1000))
              for count in range(number_of_points)]

pprint(camera_coords)
x, y, z = camera_coords[0]

new_camera_coords = [(a-x,b-y,c-z) for a, b, c in camera_coords]

print '='*80
pprint(new_camera_coords)

but it gives me errosrs:
1. too much data to unpack: "x, y, z = camera_coords[0]"
and when I sorted that one, the second one is:
2."TypeError: unsupported operand type(s) for -: 'list' and 'list'"
in part of the code: "new_camera_coords = [(a-x,b-y,c-z) for a, b, c in camera_coords]"..

do u know how to fix it?

put before the line

print camera_coords[0], type(camera_coords[0])

The error tells that you have not numeric coordinate, but list.

This article has been dead for over six months. Start a new discussion instead.