I have a .txt file which consists of x,y,z coordinates of a drone flight
example:
121.12 98.12 1.02
122.98 98.88 3.05
First column is x, second column is y, and third column is z.
I have tried with file loader and output the data to console, but now I don't know how to save x,y,z to Vector3
var loader = new THREE.FileLoader();
//load a text file and output the result to the console
loader.load(
// resource URL
'example.txt',
// onLoad callback
function ( data ) {
// output the text to the console
console.log( data )
}
Try data.split( '\n' ) in order to split your string into an array of substrings. Next, you iterate over the array and split each line like so line.split(" "). You can then parse the resulting values to floats and assign them to a new instance of Vector3.
Related
I am currently having trouble chaining a rotation transformation in a D3 line chart. The parameters for the origin are dynamically updated and I am not sure what I need to do so that each call to this batch of code rotates the line a further 15 degrees. I have tried adding a plus in front of the rotate string as per another answer I saw but it throws an error. Ideally I would like the transition to animate each time from the updated rotated position(like the hand of a clock moving).
//select the path I want to transform this works for a single time
d3.select(".demandPath1")
.transition()
.duration(2000)
.attr("transform",`rotate(-15,${xScale([demandX[5])},{yScale(demandY[5])})`)
This code will be called on the press of a button which should continually rotate the line in increments of 15 degrees starting each time from the new position.
Create a variable to store the string:
var existingTransformString="";
Use string concat method to append the new string to the existing string- which has the correct transforms stored i.e. those that have been applied to the existing path element:
function rotate(direction){
if(direction==="increase"){
let string = rotate(15,${xScale(demandX[5])},${yScale(demandY[5])});
existingTransformString = existingTransformString.concat(string);
d3.select(".demandPath1").attr("transform",existingTransformString);
}else{
let string = rotate(-15, ${xScale(demandX[5])},${yScale(demandY[5])});
existingTransformString = existingTransformString.concat(string);
d3.select(".demandPath1").attr("transform",existingTransformString);
}
}
Consider I have load a dataset as follows:
ds = yt.load('pltxxx')
The dataset includes the following fields
density, mag_vort, tracer, x_velocity, y_velocity
One can simply plot the mag_vort which is the magnitude of vorticity in 2D domain in this case, by means of:
slc = yt.SlicePlot(ds, 'z', 'mag_vort')
If I want to export the x-cooridnates, y-coordinates and vorticity_magnitude in the txt file (or numpy array) or plot it via matplotlib scatter plot
plt.scatter(x_coor, y_coor, c=mag_vort)
Is there an easy way to extract those information from dataset?
You can use a data object (in this case we use the all_data data object) to access the field values for the 'x', 'y', and 'mag_vort' fields:
ad = ds.all_data()
x = ad['x']
y = ad['y']
mag_vort = ad['mag_vort']
The arrays you get back from accessing a data object are YTArray instances. YTArray is a subclass of numpy's ndarray that has units attached.
Before you pass these arrays to matplotlib, convert them to whichever units you want to do the plot in, then cast them to numpy arrays:
x_plot = np.array(x.to('km'))
y_plot = np.array(y.to('km'))
plt.scatter(x_plot, y_plot, c=np.array(mag_vort))
I have the following code to import multiple images from one directory into a struct in Matlab, here is an example of the images.
myPath= 'E:\conduit_stl(smooth contour)\Collagen Contour Slices\'; %'
fileNames = dir(fullfile(myPath, '*.tif'));
C = cell(length(fileNames), 1);
for k = 1:length(fileNames)
filename = fileNames(k).name;
C{k} = imread(filename);
se = strel('disk', 2, 0);
C = imclose(C, se);
filled = imfill(C,'holes');
end
Though now I would like to perform a fill on all the images, later finding the centroids. However, when attempting this, an error stating: "Expected input number 1, I1 or BW1, to be one of these types: double, ... etc" I tried converting the images into double precision, though that just resulted in: "Conversion to double from cell is not possible."
This is most likely due to the structure type, the images are 'housed' in, but I have no idea concerning that.
Help on this would be greatly appreciated.
So to elaborate on my previous comments, here are a few things to change with your code:
C is not a structure but a cell array. The content of a cell array is access with {curly brackets}. If all your images are the same size, then it is more efficient to store them into a numeric array instead of a cell array. Since they seem to be logical images, your array would have 3 dimensions:
[height, width, numberofimages]
You could therefore start your code with:
myPath= 'E:\conduit_stl(smooth contour)\Collagen Contour Slices\'; %'
fileNames = dir(fullfile(myPath, '*.tif'));
%// if your images are of type uint8
C(height,width,length(fileNames)) = uint8(0);
C_filled = C; %// initialize new array to stored filled images
Also, since you are using the same structuring elements for your morphological operation on all the images, you can define it once outside the loop.
So your code could look like this:
se = strel('disk', 2, 0);
for k = 1:length(fileNames)
C(:,:,k) = imread(fileNames(k).name);
C_filled(:,:,k) = imfill(imclose(C(:,:,k), se),'holes');
end
I would like to draw dynamic vertical marker line in my chart. Position of marker is available in dataset named ml_data in column ml_position. This is a dataset with one row and one column only. Is there a way how I can get value of ml_position in javascript? Currently I have the following working example:
function beforeDrawMarkerLine(axis, markerLine, icsc)
{
importPackage(Packages.org.eclipse.birt.chart.model.data.impl);
importPackage(Packages.org.eclipse.birt.chart.model.component.impl);
var ml_value = 20;
markerLine.setValue(NumberDataElementImpl.create(ml_value)) ;
}
The value is currently fixed (20). I would like to assign value of ml_position to ml_value.
My working solution:
Create global variable "mpos" and put your chart into simple table with one row a one column. Assign dataset with ml_position to table. This is important for executing dataset onFetch script before rendering chart. Finally set following scripts:
Dataset onFetch script:
reportContext.setPersistentGlobalVariable("mpos",row["ml_position"].toString());
Chart onRender script:
function beforeDrawMarkerLine(axis, markerLine, icsc)
{
importPackage(Packages.org.eclipse.birt.chart.model.data.impl);
importPackage(Packages.org.eclipse.birt.chart.model.component.impl);
var ci = icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("mpos");
markerLine.setValue(NumberDataElementImpl.create(ci)) ;
}
I am reading a DICOMDIR and then displaying all the images of a given series one by one, either by scrolling with the mouse or by pressing the keyboard arrow keys up n down.
Now, I happen to draw a line on one of these images.
Currently, when I scroll through the images the line continues to stay on through all the images.
But the desired result is, when I start scrolling, that line should disappear because it does not belong to the next image. When I scroll back up to that image where I drew that line, the line should be shown back on that image.
Any ideas how to make that line part of only that image where it is first drawn and none else?
What I tried : Store the file path of that image (where the line is drawn) into a CStringArray. How should I use this stored file path to draw that image along with its line?
I'm not quite sure what you are trying to do. If you mean you want a line annotation for a particular image you can store it as GSPS data, read that also along with the pixel data. GreyScale Presentation State object
allows inclusion of multiple graphic annotation seqences into a single object.
Your way
As you have stored the path of the file in a CStringArray, locate the code where the image is read and displayed. Add code similar to this ( I assume that you are displaying it as you read it.) Take a look at the following code.
// Code to read the file where path is csFilePath
// Read bitmap is stored to CBitmap* pBitmap
CDC* pDC = GetDC();
CDC memDC;
memDC.CreateCompatibleDC( pDC );
CBitmap* pOldBitmap = memDC.SelectObject( pBitmap );
pDC->BitBlt( xVal, yVAl, width, height, memDc, SRC_COPY );
memDC.SelectObject( pOldBitmap );
memDC.DeleteObject();
for( int nIdx; nIdx < yourLineArray.GetSize(); nIdx++ )
{
if( csFilePath == yourLineArray[nIdx] )
{
pDC->DrawLine( x1, y1, x2, y2 );
break;
}
}