Editable Image Region - Plugin Update - Сообщения

before introducing multiple images I would suggest you to improve the code of the plugin. As for what I can see, LoadImage() is everywhere, that seems to me a waste of performances (especially for svg, psd, dxf, pdf, dwg files, where you have to read a lot of data and initialize it at any call); you should identify when the file must be accessed (when it is loaded the first time, on some specific actions, on evaluation?), everything else can be addressed using an internal resource (storing imageEo and/or the original resource in an global object)
<svg width="100%" height="100%" xmlns="http://www.w3.org/2000/svg">
This code does not work and some iteration of it should. Any ideas?
using (FileStream streamSVG = new FileStream(loadFromPath, FileMode.Open, FileAccess.ReadWrite))
{
XmlDocument svgFile = new XmlDocument();
svgFile.Load(streamSVG);
XmlElement svg = (XmlElement)svgFile.SelectSingleNode("//svg"
;
//if (!(svg.HasAttribute("viewbox"
|| svg.HasAttribute("viewBox"
|| svg.HasAttribute("Viewbox"
|| svg.HasAttribute("ViewBox"
))
//{
svg.SetAttribute("width", "100%"
; // Set to new value.
svg.SetAttribute("height", "100%"
; // Set to new value.
//}
svgFile.Save(streamSVG);
}
WroteAlex - Do you have an example(s) of how you typically use this plugin?
Thanks!
Use it all the time for:
1. Visually confirming and documenting correctness of excel_IO input output
2. Displaying part of excel sheet in SMath
For 1 and 2 you would benefit from "counter variable" formula kindly provided by Davide (to automate naming of excel screenshots)
http://en.smath.info/forum/yaf_postst7309_How-to-implement-counter-variable---function.aspx
3. Sketching. This is big. PDF is very good choice for this; here is workflow, you will need Bluebeam and Inkscape:
Method 1 (I use it 70% of the time):
- take a PDF from CAD team for further markup / sketching
- Bluebeam screen capture feature capures vector graphics (surprise!)
- insert image region, set its size on the page, select extension "PDF"
- double click to be opened in Bluebeam
- Insert copied vector graphics
- Markup, or save and open in Inkscape to edit vector graphics directly
Method 2 :
- insert image region, set its size on the page, select extension "PDF"
- double click
- markup in bluebeam - there is enough basic sketching tools for you not to need anything else
There are also supported CAD formats which you can use if you want..
Wrote... max size to upload 5.859 MB
the file of this peanut 4.19MB
REFUSED !
Here is that peanut
Hi Jean, allow me to be frank here.
It is very clear that image region is not useful much to you. Myself, and at least a couple of other people use it all the time at work, i.e. it is not "dead in the water".
I would not benefit much from overlaying a tiny teapot over a tiny persian carpet. Unfortunately use of large files is limited by the speed of matrix operations in SMath when you have 10's of the in one document, and I do.
Can we just leave it at that? This plugin is useful for some but not all..
WroteAlex,
before introducing multiple images I would suggest you to improve the code of the plugin. As for what I can see, LoadImage() is everywhere, that seems to me a waste of performances (especially for svg, psd, dxf, pdf, dwg files, where you have to read a lot of data and initialize it at any call); you should identify when the file must be accessed (when it is loaded the first time, on some specific actions, on evaluation?), everything else can be addressed using an internal resource (storing imageEo and/or the original resource in an global object)
I agree that some cleanup could be useful.. To be fair though, once LoadImage() is called, it will not reload it again till the image was changed (there is a Boolean flag for that).
So abundance of LoadImage() calls does not slow down the worksheet after initial loading.
Thanks for the explaining that. I can see this being useful for including sketches in our calculation reports.
I can't remember - do you do structural engineering?
However I'm trying to understand the difference here - I could just make a sketch then take a screen shot and paste it into the calculation. It seems that with your plugin the sketch would be permanently linked to the smath sheet. So if I opened up the pdf with some editing software, made changes or added markups, this would then update in Smath. This is the general benefit, right?
Thanks again!
WroteAlex,
Thanks for the explaining that. I can see this being useful for including sketches in our calculation reports.
I can't remember - do you do structural engineering?
However I'm trying to understand the difference here - I could just make a sketch then take a screen shot and paste it into the calculation. It seems that with your plugin the sketch would be permanently linked to the smath sheet. So if I opened up the pdf with some editing software, made changes or added markups, this would then update in Smath. This is the general benefit, right?
Thanks again!
That's the idea, the sketch file is saved within SMath workbook so you can edit it in future by double clicking. Works great for making changes to sketches you created.
You could of course take a new screenshot every time you make an edit. And keep track of the sketch files your are inserting into workbook.
I'm trying to set the width / height pramaters in the scg file by hand
<svg width="100%" height="100%" xmlns="http://www.w3.org/2000/svg">[/code][/quote]
This code does not work and some iteration of it should. Any ideas?
[code=csharp]
using (FileStream streamSVG = new FileStream(loadFromPath, FileMode.Open, FileAccess.ReadWrite))
{
XmlDocument svgFile = new XmlDocument();
svgFile.Load(streamSVG);
XmlElement svg = (XmlElement)svgFile.SelectSingleNode("//svg"
;
//if (!(svg.HasAttribute("viewbox"
|| svg.HasAttribute("viewBox"
|| svg.HasAttribute("Viewbox"
|| svg.HasAttribute("ViewBox"
))
//{
svg.SetAttribute("width", "100%"
; // Set to new value.
svg.SetAttribute("height", "100%"
; // Set to new value.
//}
svgFile.Save(streamSVG);
}
The exception is caught @ "setattribute"
"Object reference not set to an instance of an object."
if (Path.GetExtension(loadFromPath).Equals(".svg"
|| Path.GetExtension(loadFromPath).Equals(".svgz"
)
{
try
{
using (FileStream streamSVG = new FileStream(loadFromPath, FileMode.Open, FileAccess.ReadWrite))
{
XmlDocument svgFile = new XmlDocument();
svgFile.Load(streamSVG);
streamSVG.SetLength(0);
//XmlElement svg = (XmlElement)svgFile.SelectSingleNode("//svg"
;
XmlElement svg = svgFile.DocumentElement;
if (!(svg.HasAttribute("viewbox"
|| svg.HasAttribute("viewBox"
|| svg.HasAttribute("Viewbox"
|| svg.HasAttribute("ViewBox"
))
{
svg.SetAttribute("width", "100%"
; // Set to new value.
svg.SetAttribute("height", "100%"
; // Set to new value.
}
//svgFile.DocumentElement.SetAttribute("width", "100%"
;
//svgFile.DocumentElement.SetAttribute("height", "100%"
;
svgFile.Save(streamSVG);
streamSVG.Close();
}
var SVGdoc = SvgDocument.Open(loadFromPath);
if (!(SVGdoc.OwnerDocument.ViewBox.Width == 0 || SVGdoc.OwnerDocument.ViewBox.Height == 0))
{
//SVGdoc.OwnerDocument.ViewBox = new SvgViewBox(0, 0, SVGdoc.Width, SVGdoc.Height);
// SVGdoc.ViewBox = new SvgViewBox(0, 0, baseWidth, baseHeight);
if (select_rotation == "90°" || select_rotation == "270°"
{
SVGdoc.Height = Size.Width;
SVGdoc.Width = Size.Height;
}
else
{
SVGdoc.Height = Size.Height;
SVGdoc.Width = Size.Width;
}
OLDheight = Convert.ToInt32(SVGdoc.OwnerDocument.ViewBox.Height);
OLDwidht = Convert.ToInt32(SVGdoc.OwnerDocument.ViewBox.Width);
}
using (MemoryStream stream = new MemoryStream())
{
SVGdoc.Draw().Save(stream, System.Drawing.Imaging.ImageFormat.Png);
loadedImage = System.Drawing.Image.FromStream(stream);
imageWasChanged = false;
imageXml = System.Drawing.Image.FromStream(stream);
}
rotateImage(loadedImage, select_rotation);
}
catch
{
}
}
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
Once done, I could complete the fix for DISLIN .svg files.
Note that resulting svg file will be zoomable within SMath, but reset to original size will not work since the actual size of the plot is not present within .svg by DISLIN
WroteI figured out why I cannot load DISLIN generated .svg as an XML document. Its the presence of this within the .svg:
What is the quickest way to remove it from file before loading it as XML?<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
Once done, I could complete the fix for DISLIN .svg files.
Note that resulting svg file will be zoomable within SMath, but reset to original size will not work since the actual size of the plot is not present within .svg by DISLIN
I may be wrong but I guess this is because XmlDocument attempts to download the DTD
Instead of edit/removing the DOCTYPE, you can try using:
XmlDocument svgFile = new XmlDocument();
svgFile.XmlResolver = null;
Plugin was updated.
if (SVGdoc.OwnerDocument.ViewBox.Width == 0 || SVGdoc.OwnerDocument.ViewBox.Height == 0)
{
SVGdoc.Height = 1;
SVGdoc.Width = 1;
SVGdoc.Height = SVGdoc.Height.ToPercentage();
SVGdoc.Width = SVGdoc.Width.ToPercentage();
SVGdoc.OwnerDocument.ViewBox = new SvgViewBox(SVGdoc.OwnerDocument.Bounds.Left, SVGdoc.OwnerDocument.Bounds.Top, Convert.ToInt32(SVGdoc.OwnerDocument.GetDimensions().Width), Convert.ToInt32(SVGdoc.OwnerDocument.GetDimensions().Height));
SVGdoc.Height = Convert.ToInt32(SVGdoc.OwnerDocument.GetDimensions().Height);
SVGdoc.Width = Convert.ToInt32(SVGdoc.OwnerDocument.GetDimensions().Width);
}
Seems like an extremely simple piece of code now... Doesn't it always.
WroteAlex,
before introducing multiple images I would suggest you to improve the code of the plugin. As for what I can see, LoadImage() is everywhere, that seems to me a waste of performances (especially for svg, psd, dxf, pdf, dwg files, where you have to read a lot of data and initialize it at any call); you should identify when the file must be accessed (when it is loaded the first time, on some specific actions, on evaluation?), everything else can be addressed using an internal resource (storing imageEo and/or the original resource in an global object)
Davide, I made an attempt to clean up function calls.
Would love to hear your comments / suggestions if any.
Thanks
Is it possible to extend the plugin to accept matrices of 3(4)-numbers matrices (vectors/rows), where members are R, G, B (and optional Alpha)? And maybe functions to read to this structure / write it to image?
Or alternatively, a system of 3(4) usual matrices with corresponding values?
WrotePlease excuse me if this has been discussed already.
Is it possible to extend the plugin to accept matrices of 3(4)-numbers matrices (vectors/rows), where members are R, G, B (and optional Alpha)? And maybe functions to read to this structure / write it to image?
Or alternatively, a system of 3(4) usual matrices with corresponding values?
Mike, I am somewhat busy this weekend, but I will look into this mid week or next weekend. It would greatly simplify my task if you were to find a C# guide that talks about converting numerical matrices to color image.
Alex
WroteMike, I am somewhat busy this weekend, but I will look into this mid week or next weekend. It would greatly simplify my task if you were to find a C# guide that talks about converting numerical matrices to color image.
Thank you very much!
I'm not quite sure I understand what information do you mean.
I suppose that the place to change is lines starting from 349 in ImageRegion.cs (public method void ImageRegion.OnEvaluation(SMath.Math.Store store) - where it processes matrix). If you will support systems, then third choice would likely be required - "else if (obj is SMath.Math.Numeric.TSystem)" (I suppose the name is TSystem).
Lines 381-392 assign same (gray) values to R, G and B channels. I suppose, here the current mode should be kept if our matrix contains numbers, otherwise if its contents in this position is another matrix of length 3 (4), then assign R, G and B to individual channels. To do so, line 383 should change from unconditionally getting byte value, to a code that checks what is there at matrix.unit[y, x].obj, and if it is SMath.Math.Numeric.TMatrix, then extract its 3 members, otherwise go old way.
Here I see a method to set alpha channel; maybe it's good to always use alpha channel, and set it always to 0 unless it's present in the pixel?
EDIT: generating and manipulation separate R, G, B and Alpha matrices is much more efficient than matrices of matrices, so if you decide to implement this request, then please allow second variant, too (I mean system of 3(4) separate matrices).
WrotePlease excuse me if this has been discussed already.
Is it possible to extend the plugin to accept matrices of 3(4)-numbers matrices (vectors/rows), where members are R, G, B (and optional Alpha)? And maybe functions to read to this structure / write it to image?
In other words, you are asking for an RGB image region, something like the Mathcad
"Picture Operator". I found no independent tool from the web that would do same.
The Mthcad "PicOp" allows lot of useful manipulations: various color scheme, extract selected region from the image... Are you familiar with the Mathcad "PicOp" ?
That's all what I understand from Smath 5346


Once in work sheet, "Image region" does 0 processing by itself.
From external user processing, you can:
1. replace part of image
2. zoom Fourier small image [zoom up 2]
3. vetorise for light intensity.
4. mirror image, rotate +/- 90° by matrix manipulation
5. scale overal image to user grayscale.
6. what else ... extract band valued pixels, specific valued [locate]
7. more specific vetorise to highlight contour region.
..... Jean
-
Новые сообщения
-
Нет новых сообщений