Sketchup Ruby InputPoint.face method on Image object? - ruby

I have one problem with InputPoint.face method in Sketchup Ruby API.
When i import one image object and then draw 5-edges polygon on this image. I used InputPoint.face for getting number of edges in the polygon after clicking on it. I think the output is 5, but actually, the output is 4
If i remove the image , result will be 5.
I don't understand why the output is like that, and what can i do to get output 5?
This is my code
# The onLButtonDOwn method is called when the user presses the left mouse button.
def onLButtonDown(flags, x, y, view)
#ip = view.inputpoint x,y
#f = #ip.face
aEdges = #f.edges
puts aEdges.length
end
Thanks you

So you have drawn pentagon faces on the Image entity you imported? And when you use InputPoint to click on one of the pentagons you get a face with four edges?
What happens here is probably that you are getting the Face inside the Image entity. Under the hood an Image entity is a special component instance. You can in fact find the definition for the Image entity in model.definitions.
For more details on SketchUp and Components, Groups and Images read this article: http://www.thomthom.net/thoughts/2012/02/definitions-and-instances-in-sketchup/
InputPoint and PickHelper seem to let you pick the face inside the Image entity instead of stopping when it hits the Image entity.
You will probably want to filter out your results before using them and you probably wantto use the PickHelper class instead of InputPoint.
http://www.sketchup.com/intl/en/developer/docs/ourdoc/pickhelper.php
http://www.thomthom.net/thoughts/2013/01/pickhelper-a-visual-guide/
InputPoint is more for getting 3d points for inference, while PickHelper is best to use to pick and select entities.
You can check the Face entity you get from InputPoint and it's parent to verify which face it is and what context it belongs to.

Related

How can I create a pixel labelled image for Semantic Segmentation?

I am following the Semantic Segmentation Examples tutorial by MathWorks.
I understand that I can load pixel labeled images
pxDir = fullfile(dataDir,'buildingPixelLabels');
Define the class names.
classNames = ["sky" "grass" "building" "sidewalk"];
Define the label ID for each class name.
pixelLabelID = [1 2 3 4];
and create a pixelLabelDatastore.
pxds = pixelLabelDatastore(pxDir,classNames,pixelLabelID);
But, how do I create a custom pixel labelled image where every pixel value represents the categorical label of that pixel?
I would then proceed by writing:
pxDir = fullfile(dataDir,'myCustomPixelLabels');
If I understood correctly, imageDatastore holds the actual image and not the pixel labels for that image.
EDIT:
On my system pxDir points to 'C:\Program Files\MATLAB\R2017a\toolbox\vision\visiondata\buildingPixelLabels'. Since I am on Matlab2017a so this example is not included by default, and I cannot compare or view the file to get a better understanding of what I need to do to reproduce this example.
The answer can be found here.
Matlab 2017a
Go to the APPS tab, and search for Image Labeler, or Training Image Labeler
Click on Add Images to add your training images.
Click on Add ROI Labels to add class names for the regions of interest.
Proceed to select the regions of interest manually from the uploaded images.
Once areas are selected, the data can be exported to workspace as a Ground Truth object.

How to project (or paste)panorama to model?

Before question,I seached many places, I find some similar idea but without my solution.And my question can be also described as how to recalculate the model's uv to fix the panorama designed for six faces skybox.
Recently,I came upon a unique way to get fluent 3D roaming experience on matterport's Official network https://matterport.com/gallery/
I just want to know how did they do that?Their product is very fluent when swich the panorama picture.
After I roaming many times,I found the secret. I realized that the panorama carrier they use is not box or sphere,but is the object they show first!The evidence is that when switch the point,the object such as chair and table would have their own shadow(one chair have two image one stand up and the other one lie on the floor
With the object in panorama paste on their own correspond object and with depth information the roaming switch become more fluent (As for why they do not use the object directly ,I think because of the limited hardware,Many irregularity faces which get from scanning equipment cannot be use directly
And I want to use this idea in my project ,I have a group of six panorama which can paste on a boxGeometry perfectly,and I just want to paste them on model.but I stuck in project 360 degree.Yes I just find how to project one direction but I cannot project the remaining five.
var _p=BufferGeometry.attributes;
for (var i = 0; i < _p.position.count; i++){
var uvtempbeforeconvert= ( new THREE.Vector3(_p.position.array[3*i],_p.position.array[3*i+1],_p.position.array[3*i+2]) ).clone().applyMatrix4(houseObject.matrixWorld).project(camera1)
//use the worldvertices to get its screen coordinate
if(uvtempbeforeconvert.x<1&&uvtempbeforeconvert.x>-1 && uvtempbeforeconvert.y<1 &&uvtempbeforeconvert.y>-1) {
VerticesArray1.push(_p.position.array[3*i],_p.position.array[3*i+1],_p.position.array[3*i+2]);uvArray1.push(uvtempbeforeconvert.x*0.5+0.5,uvtempbeforeconvert.y*0.5+0.5);
Yes,I success in calculating one direction.BUT I cant deal with the triangle faces which occupy two more view frustum,like a face at the edge of the box.
How should I deal with this problem?Or I run in the FALSE direction at first?Which direction should i run in ?
After asking many people,I just find that I need to usd shadermaterial in threejs ,and use a function named cubetexture,samplercube.With that I can get the pixel color what I need!

What do the coordinates on the Sketchup Ruby API mean?

I'm very new to the Sketchup API and programming in general so sorry if this is a very basic question.
I tried clicking on a cuboid I drew and inputted this code to get the coordinates of the bounding box:
model = Sketchup.active_model
model_bb = model.bounds
However, sketchup returns this:
#<Geom::BoundingBox:0x0000005063c360>
What does this mean and how can I turn these into x,y,z coordinates that I can work with?
Thanks.
#<Geom::BoundingBox:0x0000005063c360>
What does this mean[?]
Its the object being returned by model.bounds and being set to model_bb. Whilst working with Ruby via the console it will echo back the last returned result.
how can I turn these into x,y,z coordinates that I can work with?
You can retrieve each of the 8 Point3d corners of the Bounding Box with its corner(corner_index) method like so
points = (0..7).map { |n| model_bb.corner(n) }
You can find out more information by reading the SketchUp Ruby API Documentation

How to find out the dimensions of a 3-D model constructed using an object file and the patch function onto the figure window?

I have attached the object file from which we are trying to find the dimensions(please open the objectfile.txt in notepad++ or sublime text as it groups the values into to rows and columns respectively). Using this object file we have plotted the image onto the figure window using Patch function. Now, what we want to achieve is to find the dimensions of the 3-D object model. We aren't able to find any useful links. The main purpose is to find the waist size and the shoulder length of the 3D model. Here's an image of the figure window.
How should we approach this problem? Is there any algorithm that we have to follow?Image of 3D model on figure window in matlab

User input on subsequent images to store coordinates

function main()
clear all;clc;
path='.\image_files\'; %___________image files path
path_posmap='.\pos_maps\';%_________stores positions of agents
NumOfImages = length(dir(path)) - 2;
w = dir(path);
img_names={}; %________stores names of all images
for i=3:NumOfImages+2,
img_names{i-2} = w(i).name;
end
for i=1:numel(img_names),
imname = [ path img_names{i}];
im0 = imread(imname);
imageHandle =imshow(im0);%_____________displays the image
xlabel(num2str(i));
set(imageHandle,'ButtonDownFcn',#ImageClickCallback);
end
end
function coordinates=ImageClickCallback ( objectHandle , eventData )
axesHandle = get(objectHandle,'Parent');
coordinates = get(axesHandle,'CurrentPoint');
coordinates = coordinates(1,1:2);
message = sprintf('x: %.1f , y: %.1f',coordinates (1) ,coordinates (2));
disp(coordinates); %___ add these coordinates for each image
close(gcf);
end
I want to display a series of images to a user. For each image request input from the user in the form of a mouse click on the image. Store the coordinates of each click in a matrix. Thus, in end having a matrix of dimension num_images x 2.
But in the above
a. I can't get the coordinates returned from the function ImageClickCallback
b. I am unable to close the image and display a new one whenever the user clicks.
I have no MATLAB here right now, so there are a couple guesses in my answer. Here we go:
Closing Figures
You don't close the image, so it won't close. Just add close gcf; at the end of your callback.
Passing Data
Now to get the coordinates I'd suggest using the base workspace instead of a global variable, or pass an argument to your callback.
Means I'd use assignin('base','newcords',coordinates); at the end of your callback.
Use evalin to get your coordinates back from the base workspace. You can try to access newcords without evalin, however I am pretty sure it isn't going to work.
newcords=evalin('base','newcords');
Now you create a new Variable (initialize it outside the for-loop), which holds all coordinates, assuming 2D-coordinates: allcords=zeros(2,numel(img_name));
Write the coordinates from the callback into your new-allcords-variable.
allcords(1,i)=newcords(1);
allcords(2,i)=newcords(2);
On Second thought you don't need to pass the coordinates back from the callback, go with:
Initialize allcords outside your loop:
allcords=zeros(2,1);
In your callback:
allcords=evalin('base',allcords);
allcordssize=size(allcords):
if min(allcordssize)=1
allcords(1,end)=coordinates(1);
allcords(2,end)=coordinates(2);
assignin('base','allcords',allcords);
else
allcords(1,end+1)=coordinates(1);
allcords(2,end+1)=coordinates(2);
assignin('base','allcords',allcords);
end
close gcf %close picture
With that you have all your coordinates from your callback. Another way you could use is, as I mentioned above, passing a variable to your callback.
Make sure data is matched with correct figure
The second problem is, your for loop does open all pictures at once I guess? (I Have no MATLAB available). So how about using uiwait(gcf); in your for loop? (After your set). This way you know which coordinates are assigned to which figure (also if all pictures are opened your coordinates are reverse to the img-list-indexes).
P.S.: I'm not sure if uiwait works in this case, what would work for sure is if you create a single GUI with just 1 handle (for your image), and instead of closing your figure just redraw your image each time your coordinates are chosen. Or load your GUI each loop-iteration, and pass the image name to the GUI.

Resources